Notesfoundations🌱 seedling
Write-Back Cache
Also: Write-Behind · Write-Back · Dirty Cache
The cache acknowledges a write as soon as it holds it, marks it dirty, and flushes to the backing store later, often in batches. Fast writes, but acknowledged data is lost if the cache dies first.
Why it exists
Writes to the backing store are slow, and many writes hit the same keys repeatedly. Absorbing them in memory and flushing later cuts both latency and store load.
How it works
- A write updates the cache and marks the entry dirty, then acknowledges.
- A background flusher writes dirty entries to the store on a timer, under memory pressure, or on eviction.
- Repeated writes to one key coalesce into one store write.
- Durability needs a separate mechanism: replication of the cache, or a Write-Ahead Log.
Trade-offs
| Gains | Costs |
|---|---|
| write latency of memory | data loss window on crash |
| fewer, batched store writes | store lags the cache; other readers of the store see old data |
| absorbs write bursts | complex recovery and ordering |
In practice
- Operating systems: the Linux page cache is write-back. By default, dirty data counts as old enough to flush after 30 s, and flusher threads wake every 5 s. That's why databases
fsyncbefore acknowledging a commit. - CPUs: write-back L1/L2 caches, kept coherent by hardware protocols.
Pitfalls
- Treating an acknowledged write as durable when it only lives in a write-back cache.
- Readers that go straight to the store see stale data until the flush.
Connections
- Part of
- Caching
- Contrasts with
- Write-Through Cache
- Related
- Write-Ahead Log
Recall
These cards are also in your review deck, scheduled with spaced repetition.