Cache Stampede on a Flash-Sale Product Page
Synchronized TTL expiry on a high-traffic product page caused every application server to hit the database simultaneously at the top of the hour.
Overview
Every product page key expired at the same second a flash sale began, and 200 servers queried PostgreSQL for the same pages at once.
What happened
Product page TTLs were exactly 3600 seconds, and every product had been cached at the last flush, exactly one hour before the flash sale started at noon, so every key expired across the fleet at the peak.
The timeline is short.
- One hour earlier, after a cache flush, every product was cached with a TTL of 3600 s.
- At 12:00:00 PM the sale started, and every key expired.
- In the first 500ms, about 4,000 concurrent queries hit the database.
- Four minutes after the start, the popular pages were cached again.
- Eighteen minutes after the start, the less popular pages were cached again.
Key concepts
- Cache stampede
- TTL jitter
- Cache lock
- Stale-while-revalidate
Interview questions
- How do you prevent a cache stampede for a high-traffic product page?
Sign up free to read the full topic
More War Stories topics
- Accidental DELETE Without a WHERE Clause in Production
- An IAM Misconfiguration That Let a Developer Become Admin
- AWS Credentials Committed to a Public GitHub Repository
- Backups That Were Never Actually Completing
- BGP Route Leak That Rerouted Traffic Through an Unexpected AS
- Blue-Green Deployment That Resulted in Split-Brain Sessions
- Connection Pool Exhaustion That Brought Down 12 Microservices
- DynamoDB Hot Partition That Throttled a Flash Sale
- Failover to a Lagging Replica Lost 4 Minutes of Orders
- Internal DNS Cache Poisoning That Redirected API Traffic
- Malicious npm Package Exfiltrated Environment Variables at Build Time
- N+1 Query Pattern That Collapsed Under Load
Start free on Cariara · Coding problems · System design studio