CDN Cache Stampede and Thundering Herd Mitigation
Cache Stampede in CDN Context
Occurs when popular cached object expires or is purged, and thousands of concurrent requests discover it missing simultaneously. Without coordination, each request generates an origin fetch. For globally distributed CDN with 200 edge PoPs, a single hot object expiring can trigger 200 simultaneous origin connections within milliseconds. If each request takes 200ms RTT and object is 5 MB, origin suddenly faces 1 GB egress and hundreds of queries in a 200ms window.
Request Coalescing
Collapses concurrent misses for same cache key into single origin fetch. When multiple edges miss simultaneously, parent tier (Origin Shield) receives all requests but issues only one to origin. Reduces origin requests by 90%+ during stampedes. Implementation: track in flight requests per key, hold arriving requests until first completes, serve all from that response.
Stale While Revalidate
Serve slightly stale content (within soft TTL) while background worker refreshes from origin. Users get immediate 20-50ms response from stale cache while refresh happens asynchronously. Eliminates user visible latency impact of cache refresh. Configure two TTLs: fresh period (serve directly), stale grace period (serve stale, trigger refresh).
TTL Jitter
Randomize expiration by ±10-20% to prevent synchronized expiration storms. Instead of 1000 objects expiring at exactly 12:00:00, spread over 11:48:00-12:12:00. Formula: TTL = base + random(-0.1*base, 0.1*base). Spreads refresh load over time window rather than creating traffic spikes.