← Lessons

quiz vs the machine

Gold1380

System Design

Write Through vs Write Back vs Write Around

How a cache handles writes decides its durability and its hit rate.

5 min read · core · beat Gold to climb

Three Ways to Handle a Write

A read cache is simple, but writes force a choice: when does the slow store get updated, and does the cache hold the new value? Three strategies cover most designs.

The Strategies

  • Write through updates the cache and the backing store together on every write. Reads after a write are fast and the store is always current, but writes pay the full latency of both.
  • Write back updates only the cache and marks the entry dirty, flushing to the store later. Writes are very fast but a crash before flush loses data.
  • Write around writes straight to the store and skips the cache. The cache fills only on later reads, which avoids polluting it with data nobody reads again.

Choosing

Write through favors consistency, write back favors write throughput, and write around favors cache purity for read heavy workloads. Many systems blend them, for example write back with a durable journal so a crash can replay unflushed writes.

Key idea

Write through is consistent but slow, write back is fast but risks loss before flush, and write around keeps the cache clean for read heavy data.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the main risk of a write back cache?

2. Why might you choose write around for a read heavy workload?

3. Which strategy keeps the backing store always current at write time?