Failure Lab · incident

Cache Stampede

Every few seconds the homepage cache entry expires, hundreds of requests rebuild it at once, and the database pool collapses.

MajorIntermediate
Loading the incident…

The incident, in text

The homepage shows three blocks (deals, trending, new arrivals). Each is built by an expensive query (~300 ms) and cached for 3 seconds. Since a traffic increase this morning, the database connection pool hits its limit every few seconds, a burst of requests time out, and then everything looks fine again.

The cache is healthy and far from full.

Symptoms

  • · Errors: “timed out waiting for a database connection”, in bursts every ~3 s
  • · Cache hit ratio high on average, but drops to zero for a moment at each burst
  • · Database pool at 100% only during the bursts

The system

  • · Users
  • · Homepage API
  • · Cache
  • · Database

The postmortem is revealed after you respond to the incident.