Write-Through vs Write-Behind vs Write-Around
On this page
Learning Objective
Compare the three write-path caching patterns on the dimensions that actually differ between them, write latency, durability guarantee, cache pollution, and behaviour under cache failure, and choose correctly for a given workload rather than defaulting to whichever is most familiar.
Concept Explanation
Read caching is about avoiding work. Write caching is about where a write is considered complete, which makes it a durability question rather than a performance one, and that is why the three write patterns differ far more from each other than the read patterns do. Choosing among them is a decision about how much data you are willing to lose, and it should be made deliberately rather than inherited from whatever the framework default happens to be.
Write-through writes to the cache and the system of record synchronously, and does not acknowledge the write until both have succeeded. The cache is therefore never stale with respect to the data it holds, which removes an entire category of invalidation problems. The costs are that every write pays the latency of both systems rather than one, and that writing into the cache on every write pollutes it with data that may never be read, which is a real problem for write-heavy workloads where the working set for reads is much smaller than the set of records being written. It also does not speed up writes at all, which surprises people who reach for it expecting a performance win. Write-through is usually paired with read-through so that the cache is authoritative for reads and always current.
Write-behind, also called write-back, acknowledges the write as soon as the cache accepts it and flushes to the system of record asynchronously, typically with batching and coalescing. This is the only write pattern that genuinely makes writes faster, and the improvement can be dramatic: a burst of a thousand increments to the same counter becomes one database write, and random writes can be sorted into sequential ones before they reach disk. The price is explicit and unavoidable: there is a window in which an acknowledged write exists only in the cache, so a cache node failure loses it. Every other complication follows from that. Ordering must be preserved when flushing so that two updates to the same record are not applied out of order, failures during flush need a retry and dead-letter path, and read-your-writes consistency only holds for readers that go through the same cache. Write-behind is the right answer for high-volume, loss-tolerant, frequently-overwritten data such as counters, view tallies, telemetry, and last-seen timestamps, and the wrong answer for anything a user would notice losing.
Write-around writes only to the system of record and does not touch the cache at all, leaving the cache to be populated lazily by subsequent reads. It is the natural partner to cache-aside and is specifically the right choice when written data is unlikely to be read soon, such as bulk imports, audit logs, or event ingestion, because it keeps the cache free of entries that would only evict something useful. Its weakness is exactly the mirror image: data that is written and then immediately read, which is extremely common in interactive applications, produces a guaranteed miss on that first read.
Two cross-cutting points matter more than the individual pattern choice. First, a system almost never uses one pattern everywhere; the right granularity is per data type. A single service can reasonably use write-through for user profile records, write-behind for view counters, and write-around for an append-only event stream, and describing the system as using one pattern is usually a sign that nobody made the choice deliberately. Second, the failure behaviour of a write-behind buffer needs to be designed, not discovered. Replicating the cache, persisting the pending-write queue, bounding the flush window, and having a defined behaviour when the backing store is unavailable for longer than the buffer can absorb are all part of choosing the pattern, not optional extras.
| Pattern | Write Latency | Data Loss Window | Cache Pollution | Typical Fit |
|---|---|---|---|---|
| Write-through | Cache plus database, in sequence | None; both are committed before acknowledgement | High; every write enters the cache whether or not it is read | Read-heavy records where staleness is unacceptable |
| Write-behind | Cache only; the fastest of the three | Everything not yet flushed, on cache node loss | High, but the pollution is the mechanism | Counters, telemetry, and frequently overwritten values |
| Write-around | Database only | None | None | Bulk loads and write-once, read-rarely data |
Worked Example: Choosing Per Data Type in One Service
The example below is a single product service with three different kinds of data. Applying one pattern to all three would be wrong in two out of three cases, which is the point: the pattern is a property of the data, not of the service.
# --- 1. Product catalog record: WRITE-THROUGH ---
# Read thousands of times per write. Stale price or stock status is a
# customer-visible correctness problem. Write volume is low, so paying
# both latencies on the write path costs almost nothing in aggregate.
update_product(id, fields):
with db.transaction():
db.update("products", id, fields)
cache.set(f"product:{id}", fields, ttl=3600) # same unit of work
return OK # acknowledged only after BOTH succeeded
# --- 2. Product view counter: WRITE-BEHIND ---
# Millions of increments per hour, nobody notices a lost handful, and the
# same key is touched repeatedly so coalescing is enormous.
record_view(id):
cache.incr(f"views:{id}") # ~0.2 ms, acknowledged immediately
return OK
flush_loop(): # every 10s, per shard
batch = cache.drain_dirty("views:*")
# 1,000,000 increments collapse into one UPDATE per product
db.bulk_update("products", [(id, "+= " + n) for id, n in batch])
# Loss window is bounded and stated: <= 10s of view counts.
# Design decisions this forces, all of which are mandatory:
# - cache replicated, so one node loss does not drop the buffer
# - flush retried with backoff; failures go to a dead-letter queue
# - backpressure if the buffer grows beyond a hard cap
# --- 3. Inventory audit log: WRITE-AROUND ---
# Append-only, written constantly, read almost never (only during an
# investigation). Caching it would evict catalog data that is actually hot.
append_audit(event):
db.insert("inventory_audit", event) # cache is never touched
return OK
# Anti-pattern: using write-through for the audit log would push millions
# of never-read entries into the cache, evicting the catalog records that
# are the entire reason the cache exists.Real-World Examples
- Modern CPUs implement exactly the write-behind and write-through distinction in their L1 and L2 caches, with write-back being the default in essentially all contemporary designs precisely because coalescing repeated writes to the same cache line before touching main memory is the single largest win available, and the loss window is closed by the fact that the cache and memory share a failure domain. The hardware case is the clearest demonstration that write-behind is chosen for throughput and is only safe when the buffer cannot fail independently of the store behind it.
- Operating system page caches use write-behind for file writes by default, which is why a write system call returns long before data is on disk and why fsync exists as an explicit, expensive way to opt out of the buffer for data that must survive a power loss. Database engines that need durability call fsync at commit for exactly this reason, and the well-documented data loss incidents that follow from filesystems or drives lying about fsync completion are the general write-behind loss window appearing in one specific and very consequential form.
Review Questions & Answers
Write-through does not make writes faster and was never intended to. It writes to both the cache and the system of record before acknowledging, so a write costs at least as much as writing to the database alone plus the cache round trip; the only thing it improves is subsequent read latency and cache freshness. Whatever performance intuition led to it probably came from the word cache. If the actual goal is write throughput, the pattern that provides it is write-behind, which acknowledges at the cache and flushes asynchronously, and the team then has to decide whether the resulting loss window is acceptable for that data. If the writes are also rarely read soon after, write-around plus cache-aside is a better fit than either, since it avoids filling the cache with entries that displace genuinely hot data.
The buffer can accumulate several updates to the same record before any of them reach the backing store. If the flush applies them concurrently or in arbitrary order, an older update can land after a newer one and the durable store ends up holding a value that was superseded, which is a permanent corruption rather than a transient staleness, since nothing will ever correct it. The problem gets worse with retries: a failed flush retried later can reapply an update that has since been overwritten. Correct implementations either coalesce all pending updates for a key into a single final value before flushing, which is the usual approach for counters and last-write-wins records, or preserve a per-key sequence and apply strictly in order, refusing to apply an update whose version is older than what the store already holds.
An append-only audit or event log is the clearest case. Entries are written at high volume and read almost never, typically only during an investigation long after the fact. Write-around sends them straight to the durable store and never touches the cache. Write-through would insert every single entry into the cache, and since the cache has a fixed capacity, those entries would evict whatever is currently there. The evicted data is precisely the hot, frequently read data the cache exists to hold, so the result is a measurably lower hit rate on the traffic that matters, more load on the database from the resulting misses, and no benefit at all on the audit reads because they were never going to hit anyway. The cache would be doing strictly harmful work.
Because the correct pattern is determined by the properties of a particular kind of data, its read-to-write ratio, how badly staleness hurts, whether loss is tolerable, and whether it will be read soon after being written, and a nontrivial service almost always contains several kinds of data with materially different answers. A single service can simultaneously want write-through for a small set of hot reference records, write-behind for high-volume counters, and write-around for an event stream. A uniform answer usually means the decision was made once at the framework or library level and never revisited per data type, which is how systems end up caching audit logs and not caching their catalog, or accepting a loss window on orders because counters needed one.