Skip to content

Redis key schema

Reference for every Redis key the gateway reads or writes. Shared contract across gateway-quota, gateway-cache, and gateway-router (the circuit breaker hint). Kept in sync with the actual implementation; if a key’s shape changes, update this file in the same change.

Key Type Purpose TTL Written by Read by
q:rps:{keyId} Hash (tokens, last_refill) Token bucket state for per-key RPS limiting 2x the bucket’s window gateway-quota Lua script gateway-quota Lua script
q:tokens:{keyId}:{yyyyMM} String (counter) Monthly token consumption for budget enforcement 40 days gateway-quota (on reservation and reconciliation) gateway-quota (on budget check)
q:reserved:{requestId} String (reserved token count) Pessimistic reservation pending reconciliation (ADR-006) 5 minutes gateway-quota (at dispatch time) gateway-quota (at reconciliation time)
q:conc:{keyId} Set (request IDs) In-flight request IDs for the concurrency cap (F5.3) 5 minutes gateway-quota (add on start, remove on completion) gateway-quota (size check)
cb:hint:{provider}:{model} String (state marker) Advisory circuit breaker hint, fast-open only (ADR-004) 30 seconds gateway-router (on local breaker OPEN transition) gateway-router (other replicas, to accelerate their own open)
cache:exact:{ns}:{hash} String (JSON response body) Hot exact-match cache ahead of Postgres route TTL gateway-cache gateway-cache
cfg:routing:version String (integer counter) Config generation counter for hot reload (F2.7) none (persists until changed) gateway-router (on reload) gateway-router (to detect stale in-memory policy, if polling is used)
  • The token bucket (q:rps:{keyId}) is read, refilled, checked, and decremented in a single Lua script, never as separate round trips; doing it as three calls is a race under concurrent load, and the quota subsystem’s biggest correctness risk.
  • q:reserved:{requestId}’s 5-minute TTL is the safety net for a request that fails or crashes before reconciliation runs; the TTL must be set on every write, not just the happy path.
  • cb:hint:{provider}:{model} may only ever be used to open a breaker faster (fast-open). It must never be read to justify closing a breaker; only local, direct recovery evidence may do that (ADR-004).
  • cfg:routing:version is reserved in the schema but not currently written or read by the gateway: each replica reloads its own routing policy on POST /admin/routes/reload (or a restart).