Problem Statement
Redis infrastructure is defined in Terraform (ElastiCache parameter group with redis7 and allkeys-lru eviction policy) but no caching logic is implemented in the application. Every gist query — including repeated spatial queries within the same radius — hits PostgreSQL directly, creating unnecessary read load.
Evidence
infrastructure/terraform/redis-parameters.tf — Redis parameter group defined
- No Redis client or caching logic in Backend source code
- Every findNearby, findOne call hits PostgreSQL
Impact
High read load on primary database. No read load distribution. Slower response times for repeated queries.
Proposed Solution
- Install ioredis and @nestjs/bull (or @liaoliaots/nestjs-redis) for NestJS Redis integration
- Configure Redis connection from environment variables
- Cache findNearby results with TTL based on query parameters (lat, lon, radius, limit)
- Cache findOne results by gist ID with TTL
- Invalidate cache on new gist creation
- Add cache hit/miss metrics
Technical Requirements
- Cache key format:
gist:nearby:{lat}:{lon}:{radius}:{limit}
- Cache TTL: 60 seconds for nearby, 300 seconds for single gist
- Must handle cache invalidation on new gist creation
- Must gracefully degrade if Redis is unavailable
- Must not cache paginated results incorrectly
Acceptance Criteria
- First query misses cache, hits DB, populates cache
- Second identical query returns from cache (no DB hit)
- New gist creation invalidates nearby cache for that area
- Redis unavailability does not crash the application
- Cache hit rate is logged/metrics available
- All existing tests pass
File Inventory
Backend/src/gists/gists.service.ts
Backend/src/gists/gist.repository.ts
Backend/src/app.module.ts
Backend/package.json
Dependencies
None.
Testing Strategy
- Unit test: service layer with mocked Redis
- Integration test: running Redis, verify cache behavior
- Performance test: compare response times with and without cache
Security Considerations
Cache should not store sensitive data. Redis should require authentication in production.
Definition of Done
Problem Statement
Redis infrastructure is defined in Terraform (ElastiCache parameter group with redis7 and allkeys-lru eviction policy) but no caching logic is implemented in the application. Every gist query — including repeated spatial queries within the same radius — hits PostgreSQL directly, creating unnecessary read load.
Evidence
infrastructure/terraform/redis-parameters.tf— Redis parameter group definedImpact
High read load on primary database. No read load distribution. Slower response times for repeated queries.
Proposed Solution
Technical Requirements
gist:nearby:{lat}:{lon}:{radius}:{limit}Acceptance Criteria
File Inventory
Backend/src/gists/gists.service.tsBackend/src/gists/gist.repository.tsBackend/src/app.module.tsBackend/package.jsonDependencies
None.
Testing Strategy
Security Considerations
Cache should not store sensitive data. Redis should require authentication in production.
Definition of Done