Q: A high-traffic e-commerce landing page experiences a Redis cache expiration on a hot product catalog key ('catalog:flash_sale:2026'). 50,000 concurrent requests hit the cache simultaneously, find a cache MISS, and dogpile the underlying PostgreSQL database, instantly driving RDS CPU to 100% and taking down checkout. Simultaneously, malicious scrapers query non-existent product IDs, causing continuous cache penetration. How do you eliminate the thundering herd and cache penetration?
Protect relational databases from instant collapse during hot key cache expirations and malicious cache penetration attacks using distributed locks, XFetch probabilistic caching, and Bloom filters.
Want to master this scenario in a live sandbox? KodeKloud's PostgreSQL Database Administration & High Availability Course covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: Cache stampede (or thundering herd / dogpiling) occurs when a heavily queried cache key expires, causing concurrent application threads to simultaneously compute the expensive query and hit the database. Cache penetration occurs when queries for non-existent entities bypass the cache entirely because the keys are never present, continuously thrashing the database.
Situation: Hot Key Expiry Triggers Database Overload
Task: Eliminate Database Dogpiling & Block Non-Existent Entity Penetration
Action: Mutex Locking, Probabilistic Early Expiration (XFetch) & Bloom Filters
Result: 99.8% RDS Query Reduction & Sub-5ms p99 Latency
- Cache stampede occurs when thousands of concurrent threads query the database on a single key expiration.
- Use distributed mutex locks or probabilistic early background refresh to ensure only 1 worker queries the database.
- Use RedisBloom filters to block non-existent queries before they ever reach the persistent database layer.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Applying exclusive-lock DDL table migrations on live production databases during peak traffic windows when configuring Redis Cache Stampede DDL migrations that acquire an exclusive table lock block all concurrent queries, queuing connections until the database connection pool exhausts.
- Allowing high-frequency queries to trigger full table scans without appropriate composite indexing when configuring Redis Cache Stampede Sequential table scans saturate database CPU and disk I/O, evicting frequently queried data from the buffer cache and causing cascading timeouts.
- Disabling referential integrity constraints during bulk ETL imports without post-import consistency validation when configuring Redis Cache Stampede Skipping relational consistency checks risks introducing orphaned records and referential integrity violations into production tables.
- Relying on database snapshot backups that have never been verified through automated restoration drills when configuring Redis Cache Stampede Backups that have never been tested with automated restore verification frequently fail during real disaster recovery scenarios.