AlgoViz

Choosing a cache pattern

medium 24 min

Cache-aside, write-through and write-back differ in what happens on a save, what a reader can see and what a crash can take.

Where it shows up

The same pattern appears across everyday software.

  • Facebook memcache: cache-aside

    The NSDI 2013 paper describes a demand-filled look-aside cache in which web servers delete cached data after updating the database.

  • Facebook TAO: a cache that owns writes

    The ATC 2013 paper lists problems of look-aside caching for lists of connections, and sends all writes for a shard through one leader cache.

  • DynamoDB Accelerator: write-through

    DAX writes to the table and then to its item cache. Its nodes agree after a short moment, so an application must accept slightly old reads or ask for a strongly consistent read.

  • PostgreSQL: write-back made safe

    Changed pages are written at checkpoints, but the change is in the write-ahead log first. It shows how to defer writes without losing them.

  • A forum

    Posts are cache-aside, because popular threads stay warm by themselves. View counts are write-back. Account settings are written through.

  • Game backend

    Scores go into a sorted set and are flushed every few seconds. Purchases in the same game are database transactions without a cache.

  • Sensor platform

    The latest reading per sensor sits in memory and is stored in batches. When every reading matters, a durable log takes them first.