Single-flight caching pattern prevents cache stampede and database overload
A Russian apartment listings platform, podbor-minuta.ru, experienced mass request timeouts when a cached database query expired under heavy traffic, causing up to 200 simultaneous identical queries to overwhelm the connection pool. The phenomenon, known as a cache stampede, occurs when a cache key expires at the same moment many requests arrive, each independently triggering the same expensive computation. The team resolved this by implementing a single-flight caching pattern, where the first request to find a missing cache key creates a shared in-flight promise that all concurrent callers await together. This ensures only one database query is executed per key at any given time, regardless of how many requests arrive simultaneously. After the fix, the same traffic load that previously drained the connection pool now produces just one database query per hot key instead of hundreds.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in