All Questions
Caching hard

In a Cache-Aside system, a race condition causes permanent staleness: (1) Reader fetches stale data V1 from DB. (2) Writer updates DB to V2 and deletes cache. (3) Reader writes V1 to cache. The cache now holds V1, but the DB holds V2. How does Facebook's 'Lease' mechanism (Memcached) prevent this?

  1. A It enforces a distributed 2-Phase Commit between the Memcached cluster and the primary MySQL writer to ensure atomic state transitions.
  2. B The Reader obtains a unique lease token on a miss; if a Writer invalidates the key before the Reader's update, the write-back is discarded.
  3. C It utilizes a pessimistic locking strategy that forces every incoming GET request to acquire a shared read lock on the underlying database row.
  4. D It leverages Vector Clocks to detect causality violations and merges the divergent V1 and V2 values using a custom conflict resolution policy.

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

Get the app

Related questions