Skip to content

Design a Distributed Cache (Memcache), stage 2 of 9: break it

A stale value that never leaves

Two web servers, A and B, touched the same key around the same time. Find the lines that explain why the cache holds the old value indefinitely.

System so far· 5 parts
1234CLIENTUsersSERVICEWeb serversSERVICEmcrouterCACHEmemcached poolDATABASEMySQL

Select a component to see what it is responsible for and which state it owns.

  1. 1Users → Web servers: Page request
  2. 2Web servers → mcrouter: get / multiget, delete
  3. 3mcrouter → memcached pool: Keys by consistent hash
  4. 4Web servers → MySQL: Query on miss; writes

What you need to know

0 of 2 checks done
  1. A reader that misses does two things at two different times: it reads the database, then later sets the cache. Anything can happen in between, including a write and its delete.

    If the write's delete arrives before the reader's set, the delete has nothing to remove, and the set then stores a value read before the write.

  2. Check

    The stale value 'Ann' is now in the cache, with no TTL. How long does it stay?