Case Study · Caching · 2023 — 2024
Caching layer that absorbs read load with TTL-based invalidation and a database fallback on miss.
Read-heavy endpoints were hitting the primary database on every request, driving up latency and cost. Naive caching risked serving stale data — unacceptable for things like balances and statuses — so the system needed a cache that was fast on the hot path but never silently wrong.
A serverless deployment where database connections are scarce and cold reads are expensive. The cache had to work over HTTP (Upstash) to fit the serverless model, while keeping a clear, predictable invalidation story.
Request path
Client
request
Backend API
lookup
Redis
hit?
DB fallback
on miss
Cache set
with TTL
Failure recovery & consistency
Write
data changes
Invalidate
key
Next read
miss
Refill
fresh value
Cache layer
Rate limiting
Sessions
Chose
·Bounded-staleness TTL + active invalidation
·HTTP Redis to fit the serverless model
·Database fallback on every miss
Gave up
·Always-perfectly-fresh reads (TTL allows a small window)
·Lowest-possible latency of a socket connection
·Cache-only operation (DB stays the source of truth)
↓ load
read traffic absorbed before the database
bounded
staleness capped by explicit per-key TTL
0
connection-exhaustion incidents in serverless