Cache Stampede Interview Questions
How would you prevent a cache stampede (thundering herd)? — spoken sample answer for Indian interviews.
- 5Questions with answers
- 3Difficulty levels
Questions (5)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
How would you prevent a cache stampede (thundering herd)?
A stampede is when a hot key expires and thousands of requests miss together and all hit the database. What I would do: one request rebuilds the cache using SET key NX EX as a lock, others wait or serve slightly stale data. I also jitter TTLs so keys do not expire on the same second, and I pre-warm keys I know will be hot before a sale. Request coalescing in the app — one in-flight DB call per key — is the same idea. I would not only 'add more Redis'. The bug is synchronized expiry on a hot key.
Besides a lock, how do you stop stampede?
Jitter TTLs, stale-while-revalidate, singleflight. I would not only extend TTL forever. I have seen a celebrity key expire on the hour.
Singleflight with Redis?
SET lock NX EX 10. Winner fills. Others retry GET. Lock must expire or we deadlock. I would not wait forever. NX plus TTL every time I say lock.
Stampede — Redis bug or app bug?
App allowed a hot key to expire and thundering-herd the DB. I would not blame Redis. I would show the miss-storm graph. The pattern is ours.
Hot key that does not fit one instance?
Local in-process cache with short TTL, or replicate the value. Cluster does not help if all traffic is one key. I would not blindly add nodes.
Practice with AI mock interviews
Run Redis mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required