Skip to content

0005 — Redis for cache, locks, throttling

Status: reconstructed — needs confirmation

Context

Several backend concerns need fast shared state: live price caching, portfolio summary caching, one-shot locks, and rate limiting.

Decision

Redis 7 (redis:7-alpine, password-protected, 512 MB LRU cap in deploy/docker-compose.yml) accessed through a thin wrapper (libs/redis/src/redis.service.ts: getJson/setJson/lockOnce/ incrWithTtl). Uses in code include the SafeGold price cache (libs/safegold), portfolio summary cache (apps/api/.../portfolio.service.ts), admin config/flags/limits storage (apps/admin-api/.../config.service.ts), and the deploy double-fire lock (devops.service.ts, SET NX EX 60).

Consequences

  • Redis is a hard runtime dependency of both APIs.
  • Feature flags and admin-set limits live only in Redis — they are configuration state, not schema, and are lost if the Redis volume is lost.