Summary
Redis distributed locks (via SET NX EX or Redlock) prevent thundering herd by ensuring only one caller repopulates a cache entry at a time, with other callers either waiting or returning a stale value until the cache is warm.
Evidence
- ·Redis SET key value NX EX ttl atomically sets a lock only if absent: enables single-caller cache population
- ·Facebook's Memcache paper (NSDI 2013) documents lease-based thundering herd prevention as a core technique
- ·Twitter uses Redis locks to prevent cache stampede on trending topic cache misses
- ·Probabilistic early expiration (PER) refreshes cache slightly before expiry: avoids simultaneous expiry
- ·Redis Lua scripts enable atomic check-and-set for lock acquisition and release
Operational Context
- ·Lock TTL must be set longer than the cache population time: if it expires before population completes, lock is acquired again
- ·Callers that fail to acquire the lock should serve stale data (if available) rather than wait: reduces latency spike
- ·Monitor lock acquisition rate: sustained high lock contention indicates the cache miss rate is too high
Tradeoffs
- ·Distributed locking adds one Redis round-trip to every cache miss that triggers population
- ·If the lock holder crashes mid-population, the lock TTL must expire before recovery: causing a cache gap
- ·Redlock (multi-node locking) adds complexity: for most cache stampede cases, single-node SET NX is sufficient
Evidence grounding
Grounded, 5 supporting itemsDistributed cache lock-based thundering herd prevention is widely documented and used in production at Twitter, Facebook, and most large-scale web systems. The pattern is well-understood with clear failure modes.