Video in progress
The Redis cache cluster suddenly went down and the DB started collapsing under the load. How do you protect against that in advance?
While the cache works, the DB sees only a small share of "misses"; when the cache goes down, the entire read load hits the DB. Protection: replicas and failover for the cache, a local cache layer inside the application, limiting requests that go to the DB, and warming the cache up step by step on recovery.
📖 Answer
The math is simple. 20,000 QPS of reads with a 95% hit rate — the DB sees 1,000 QPS and is sized for that. Redis goes down — the DB gets 20,000 QPS, 20 times more. The connection pools fill up, requests queue, timeouts trigger retries and the load grows even more.
What helps:
First of all, make the cache itself reliable: Redis Sentinel or Redis Cluster with replicas, in different zones. A failover takes a few seconds — you need to be able to survive those seconds too.
A two-layer cache. A small Caffeine cache in each instance (10–60 second TTL) holds the hottest keys. When Redis goes down, this layer absorbs a large part of the load.
Protect the DB. A bulkhead or semaphore for queries going to the DB: at most, say, 50 at a time. The rest immediately get a fallback or a 503. The DB stays alive and part of the system works — better than everything going down at once.
The cache client should have a timeout and a circuit breaker. If Redis doesn't respond, each request shouldn't wait 2 seconds; once the breaker opens, go straight to the DB or the local cache.
Warm-up is needed on recovery. When an empty Redis comes back up, don't return all the traffic at once, or preload the most popular keys.
And test this: turn Redis off in staging and measure what happens to the DB. Many teams think of the cache as an "optimization", when it's actually already a load-bearing part of the system.
Sign up to mark studied questions and save your progress.