30
Backend
06
Security
12
iOS
21
Infra

Keep Redis as one Sentinel-managed store for signals, counters and OAuth state

ADR-0103 ACCEPTED · 2026-11-17
Keep Redis as one Sentinel-managed store for signals, counters and OAuth state

Amends ADR-0055: previews share one Redis database, kept apart by key prefixes, and production uses another. Amends ADR-0098, written when a separate cache tier ran beside the store.

Decision

Keep Redis in the stack after sessions left it (ADR-0028), for state that every app instance must share and that Postgres need not hold. It carries the pub/sub channels that fan subscription signals out to every node (ADR-0041), the fixed-window counters behind credential throttling (ADR-0086) and the per-user spend budgets on model calls, and the MCP authorization server's codes, client registrations and refresh tokens, each with a TTL (ADR-0063).

Run it as one tier: a Redis server on every node, one master and the rest replicas, with a Sentinel on every node electing the master by majority. The tier persists to disk with an append-only file and never evicts keys. A master refuses writes while no replica is connected. The app finds the master through Sentinel, and each environment prefixes its keys and channels.

Why

None of this data is a record of the user's trips. Signals are best effort and gone once delivered, counters and OAuth codes expire on their own, and Redis expires keys natively where Postgres would need a sweeper. A credential flood charges a counter on every attempt, and in Redis those writes never reach the Postgres primary.

Everything left in Redis must survive memory pressure, since an evicted counter resets a throttle and an evicted refresh token signs an MCP client out. An evicting cache tier ran beside the store. Pub/sub and the counters moved off it to the store because an eviction there could lose them. Its last use was a weather cache, and once weather moved on-device it served nothing, so we removed it.

High availability matters because the counters fail closed: with Redis down, every charged action, sign-in included, is refused.

Rejected alternatives

  • Postgres for all of it, with LISTEN/NOTIFY for signals and tables for counters and OAuth state. It adds attacker-driven writes and expiry sweeps to the primary, and every node would hold a listening connection to the primary that a failover drops.
  • A single Redis node. Its loss refuses every sign-in until it returns.
  • Redis Cluster. The data fits in one node's memory, so sharding buys nothing and adds slot-aware clients and multi-key restrictions.

Consequences

Redis is a second replicated store to run beside Postgres, with its own failover. Replication is asynchronous, so writes the old master accepted just before a failover can be lost, which at worst means an MCP client authorizes again. Pub/sub delivers only to subscribers connected at the moment of publishing, so a node that is reconnecting misses signals and its clients catch up on their next pull.