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

Start free on Cariara · Coding problems · System design studio