← Back to docs

Recipe: Multi-tier cache design

L1 memory → L2 Redis → L3 origin. Deterministic TTLs, circuit breakers, and offline grace.

Tier topology

Request
  │
  ▼
┌──────────────┐
│  L1  in-mem  │  TTL 30s · per-process LRU
└──────┬───────┘
       │ miss
       ▼
┌──────────────┐
│  L2  Redis   │  TTL 300s · shared across pods
└──────┬───────┘
       │ miss
       ▼
┌──────────────┐
│  L3  origin  │  compute + populate L2 → L1
└──────────────┘

Circuit breaker

When Redis is unreachable, the breaker opens after 3 consecutive failures. L1 continues serving stale data for up to 600 s. A half-open probe fires every 30 s; on success the breaker resets and L2 repopulates.

Offline grace

If both L1 and L2 are cold and origin is down, the client falls back to an HMAC-signed local cache file written during the last healthy cycle. The file carries a 24 h max-age and is invalidated on next successful origin fetch.

Key schema

TierKey patternTTL
L1lic:{hid}:v230 s
L2lic:{hid}:v2300 s
Gracegrace:{hid}.dat24 h