Skip to content

Design a Distributed Cache (Memcache), stage 7 of 9: change it

A second region

Replicas can lag behind the master. Caches in the replica region are filled from the local replica.

System so far· 7 parts
1234567CLIENTUsersSERVICEWeb serversSERVICEmcrouterCACHEmemcached poolCACHEGutter poolDATABASEMySQLWORKERInvalidationdaemon

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
  5. 5MySQL → Invalidation daemon: Committed deletes
  6. 6Invalidation daemon → mcrouter: Batched deletes
  7. 7mcrouter → Gutter pool: On server failure
  • Request / response
  • Bulk data
  • Asynchronous

What you need to know

0 of 2 checks done
  1. With replication, writes go to a primary and are copied to replicas some time later: usually under a second, sometimes much longer. A replica that hasn't received a write yet serves the old data. See Replication.

    A cache filled from a lagging replica stores that old data.

  2. Think first

    The master region writes, then immediately sends a delete to the replica region's cache. The data arrives at the replica 2 seconds later. A read in the replica region happens in between. What gets cached?