Redis

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.

Question 1
Interview Advanced
Question

How would you prevent a cache stampede (thundering herd)?

Answer:

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.

Question 2
Interview Intermediate
Question

Besides a lock, how do you stop stampede?

Answer:

Jitter TTLs, stale-while-revalidate, singleflight. I would not only extend TTL forever. I have seen a celebrity key expire on the hour.

Question 3
Interview Advanced
Question

Singleflight with Redis?

Answer:

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.

Question 4
Interview Beginner
Question

Stampede — Redis bug or app bug?

Answer:

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.

Question 5
Interview Advanced
Question

Hot key that does not fit one instance?

Answer:

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