All Questions
Dealing With Contention hard

A popular cache key expires. 10,000 requests try to read it, find it missing, and ALL query the DB to recompute it. This crashes the DB. What is the standard pattern to prevent this?

  1. A Sharding the database.
  2. B Increasing the cache size.
  3. C Singleflight (Request Coalescing). The first request acquires a lock to recompute. The other 9,999 requests block and wait for the first request to finish, then share the result.
  4. D Disabling the cache.

One system design question a day, with spaced repetition so the ones you miss come back.

Get the app

Related questions