Redis GET Response Cache
Related: Access caching strategy (Auth access only — separate from this document).
Status
Section titled “Status”FINAL for product data backends (Promoters, MusicData, Finance, Artists, Venues).
Auth session Redis and Checkout transactional Redis are out of scope here.
1. Purpose
Section titled “1. Purpose”Standardize GET response caching in data-processing backends via one global middleware per service. Frontends do not use Redis.
2. Request flow
Section titled “2. Request flow”┌──────────┐ ┌──────────┐ ┌─────────────────────┐ ┌─────────────┐│ Browser │ ───► │ Frontend │ ───► │ DATA BACKEND │ ───► │ Redis │└──────────┘ └──────────┘ │ │ │ fast copy │ │ Promoters │ └──────┬──────┘ │ MusicData │ │ │ Finance │ │ empty? │ Artists │ ▼ │ Venues │ ┌─────────────┐ └─────────────────────┘ │ DB / API │ │ real data │ └─────────────┘Cold cache: Backend → Redis (miss) → DB/API → write Redis → response.
Warm cache: Backend → Redis (hit) → response.
Backend Admin: no Redis — live data only.
3. Scope
Section titled “3. Scope”| Layer | Redis |
|---|---|
| Frontends (Admin, Artists, Finance, Promoters, Venues) | No |
| Backend Admin | No |
| Backends Promoters, MusicData, Finance, Artists, Venues | Yes — GET middleware only |
4. Middleware contract
Section titled “4. Middleware contract”- GET only — POST/PATCH/PUT/DELETE never use response cache.
- Bypass read (still write after handler):
- Query:
?live=true - Header:
x-redis: bypass liveis stripped from the cache key so bypass and normal requests share one entry.
- Query:
- Cache key:
{prefix}:{METHOD}:{path}:{sortedQueryHash}:{xOrgOrAnonymous}- Prefix examples:
promoters:,musicdata:,finance:,artists:,venues: x-orgheader when present;anonwhen absent.
- Prefix examples:
- Response header:
X-Cache: HIT | MISS | BYPASS | DISABLED - Startup: fail-open — if Redis is down, backend starts and serves live data.
- Skip paths:
/health,/ready,/docs,/swagger,/api-docs, MusicData/crontab/*
5. Environment variables (per data backend)
Section titled “5. Environment variables (per data backend)”| Variable | Purpose |
|---|---|
REDIS_URL | Preferred connection string |
REDIS_HOST, REDIS_PORT, REDIS_PASSWORD, REDIS_DB | Alternative to URL |
REDIS_CACHE_TTL_SECONDS | Global TTL for that backend |
REDIS_CACHE_ENABLED=false | Disable cache (local dev) |
Default TTL
Section titled “Default TTL”| Backend | Default REDIS_CACHE_TTL_SECONDS |
|---|---|
| Finance | 300 (5 min) |
| Promoters | 604800 (7 days) |
| MusicData | 604800 (7 days) |
| Artists | 604800 (7 days) |
| Venues | 604800 (7 days) |
6. Frontend bypass
Section titled “6. Frontend bypass”When the frontend bypass env is true, the shared API client sends x-redis: bypass on every backend request.
| Frontend | Env var |
|---|---|
| Next.js (Admin, Finance, Promoters) | NEXT_PUBLIC_REDIS_BYPASS=true |
| Vite (Artists, Venues) | VITE_REDIS_BYPASS=true |
Direct API callers may use ?live=true or x-redis: bypass without frontend env.
Frontends use short React Query staleTime (minutes); long TTL lives on the backend.
6.1 Bypass chain (BFF → data backend)
Section titled “6.1 Bypass chain (BFF → data backend)”x-redis: bypass must propagate on every server-to-server hop until the leaf data backend that owns GET Redis middleware. Each hop:
- Detects bypass on the inbound request (
x-redis: bypassor?live=trueon GET). - Skips its own Redis read when bypass is active (
X-Cache: BYPASS). - Forwards
x-redis: bypasson outbound HTTP to other Kisum data backends in the same request context.
sequenceDiagram participant FE as Frontend participant PR as Promoters participant MD as MusicData FE->>PR: GET + x-redis: bypass Note over PR: X-Cache: BYPASS PR->>MD: GET + x-redis: bypass Note over MD: X-Cache: BYPASS
Implemented propagation:
| Service | Capture | Outbound |
|---|---|---|
| Promoters | redisBypassContextMiddleware (AsyncLocalStorage) | musicdata.client, artists.client, venues.client, finance-api-client, Auth/Core clients, network proxy controllers |
| MusicData | redisBypassContextMiddleware | mergeRedisBypassPropagationHeaders helper (leaf for most routes) |
| Finance | Request ALS redisBypass | auth-service-http, core-service-http |
| Artists / Venues (Go) | redisbypass.CaptureMiddleware | redisbypass.ApplyOutbound on Finance HTTP clients |
Auth and Core do not use GET response-cache middleware; forwarding bypass to them is harmless and keeps the chain consistent.
7. Distinct Redis uses (not this middleware)
Section titled “7. Distinct Redis uses (not this middleware)”| Service | Redis role |
|---|---|
| Auth | Sessions, revocation, x-org map — not GET response cache |
| Checkout | Pending signup / provision state — not HTTP cache |
Promoters and Finance must not cache Auth /auth/me/access locally; call Auth live.
8. Verification
Section titled “8. Verification”- Repeat
GET→ second responseX-Cache: HIT GET?live=trueorx-redis: bypass→X-Cache: BYPASS; next normalGETcanHIT- Frontend
NEXT_PUBLIC_REDIS_BYPASS=true/VITE_REDIS_BYPASS=true→ browser sends bypass; each hop in §6.1 should also returnBYPASS(e.g. Promoters and MusicData on chained artist overview calls) - Redis stopped → backend boots; GETs return live data
POST/PATCH→ noX-Cacheheader