AlgoViz

Thundering herd

medium 24 min

A thundering herd, or cache stampede, happens when many requests find the same cached value missing at the same moment and all rebuild it.

Where it shows up

The same pattern appears across everyday software.

  • Facebook's memcache

    Leases let one client refill a key while others are told to wait a short time. The 2013 paper reports the measured effect.

  • Go services

    The singleflight package makes sure only one execution for a key is in flight and hands the result to every caller.

  • nginx as a cache

    With proxy_cache_lock on, one request fills a new cache element and the others wait, up to a timeout.

  • CloudFront

    Simultaneous requests for the same object are collapsed at the edge instead of all going to the origin.

  • Ticket sales

    Everybody opens the event page at 10:00. If its cached copy is missing then, thousands rebuild it together.

  • Deployments

    A new version changes the cache key prefix. Every key is suddenly missing, as if the cache had restarted.