Write-back cache for high-frequency counters

DesignHard45 minMeta style

Your task

Design the caching strategy for a write-heavy counter system: per-post view/like counts for a content platform with 1M writes/sec (increments) but reads that tolerate slight staleness. Write-through to the database on every increment would overwhelm it. Design a write-back / write-behind cache that absorbs increments in memory and flushes aggregates to durable storage, and address the hard parts: what happens to in-memory increments if a cache node crashes before flush, how you avoid losing or double-counting, and how reads see a coherent value.

It covers

  • Write heavy
  • Write back
  • Durability