Skip to content

Data Storage Layer #20

@Villarley

Description

@Villarley

Data Storage Layer - Cache and temporary persistence with Redis

📝 Description

Implement a storage layer using Redis to cache aggregated prices, maintain recent historical data, and facilitate fast access to prices by the API service. This layer should handle automatic expiration and provide efficient read/write methods.

Context: Aggregated prices need to be temporarily stored so the API service can query them quickly. We also need to maintain a recent history for trend calculations and analysis.

Tech Stack:

  • NestJS with @nestjs/cache-manager or ioredis
  • Redis as cache store
  • RxJS for asynchronous operations
  • TypeScript with strict types

✅ Requirements

  • Implement a StorageService that uses Redis as backend
  • Store aggregated prices with configurable TTL (e.g., 5 minutes)
  • Implement methods to read/write prices by symbol
  • Maintain price history (time-series) per symbol
  • Implement batch operations for multiple symbols
  • Handle automatic reconnection to Redis in case of failure
  • Implement efficient data serialization/deserialization
  • Add cache hits/misses metrics
  • Configure Redis connection via environment variables

🎯 Acceptance Criteria

  • The service successfully connects to Redis on startup
  • Prices are stored with TTL and expire automatically
  • Individual prices can be read/written by symbol
  • Price history can be obtained (last N records)
  • Batch operations work correctly for multiple symbols
  • The service handles Redis reconnections automatically
  • Cache hits/misses metrics are logged
  • Unit tests exist with Redis mocks (>80% coverage)
  • The data schema stored in Redis is documented

📁 Expected files to change/structure

  • apps/aggregator/src/services/storage.service.ts - Main service
  • apps/aggregator/src/services/storage.service.spec.ts - Tests
  • apps/aggregator/src/config/redis.config.ts - Redis configuration
  • apps/aggregator/src/interfaces/storage-options.interface.ts - Storage options
  • apps/aggregator/src/app.module.ts - Register CacheModule and service
  • apps/aggregator/package.json - Add dependencies (cache-manager, ioredis)
  • apps/aggregator/.env.example - Redis variables
  • apps/aggregator/README.md - Document Redis usage
  • docker-compose.yml (root) - Add Redis service

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions