Q: A Redis cache server is placed in front of a slow database. During a major marketing campaign launch, the cache suddenly purges its keys, and the database instantly crashes under the thundering herd of traffic. What is this phenomenon called, and how do you mitigate it?
This is called a Cache Stampede (or Thundering Herd). It happens when a highly popular cached key expires. Instantly, thousands of concur...
#General DevOps #General DevOps — Scenario-Based Interview Questions #L2 #DevOps #SRE #Architecture
🎙️ Candidate Opening & Architectural Context
""When an interviewer asks about this scenario, I explain how we balanced incident response with long-term prevention. The interviewer is testing: Cache stampede, cache penetration/misses, jitter.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
Advertisement
🛠️ Production Runbook & Step-by-Step Resolution
1️⃣
Initial Diagnostics & Root Cause Analysis
This is called a Cache Stampede (or Thundering Herd). It happens when a highly popular cached key expires. Instantly, thousands of concurrent requests hit the cache, find a miss, and *all* of them simultaneously bypass the cache and query the database to regenerate the exact same data, crashing the database.
- Adding Jitter: Instead of setting a strict 1-hour expiration on keys, add random jitter (e.g., 60 minutes + random 0 to 5 minutes) so keys expire staggeringly, preventing massive simultaneous purges.
- Mutex Locks: When a cache miss occurs, the first thread acquires a distributed lock (e.g., Redis
SETNX) for that specific key. It proceeds to query the database. The other 999 concurrent threads fail to get the lock, and sleep/poll for 50ms until the first thread populates the cache for them.
2️⃣
Remediation & Permanent Safeguards
Mitigation strategies:
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Adding Jitter: Instead of setting a strict 1-hour expiration on keys, add random jitter (e.g., 60 minutes + random 0 to 5 minutes)."
⚡ 60-Second Elevator Pitch Talking Points
- Adding Jitter: Instead of setting a strict 1-hour expiration on keys, add random jitter (e.g., 60...
- Mutex Locks: When a cache miss occurs, the first thread acquires a distributed lock (e.g., Redis ...
Advertisement