Write-Through Cache
Every write updates both the cache and the database synchronously, keeping the cache always fresh at the cost of higher write latency.
By Ratish Jain · Updated
Definition
In a write-through cache, every write goes to the cache and the backing database synchronously, as part of the same operation. The write is only acknowledged to the caller once both stores are updated.
The cache always holds the latest value, so reads are consistent with the database and never serve stale data written through this path.
The Problem It Solves
With cache-aside, the cache can miss or hold stale data after writes, forcing careful invalidation. Write-through keeps the cache and database in lockstep, so a subsequent read is guaranteed a hit with correct data.
It suits workloads where data is read soon after it's written and consistency matters more than write speed.
How It Works
- 1The application issues a write to the cache layer.
- 2The cache stores the new value.
- 3The cache synchronously writes the same value to the database.
- 4Once the database confirms, the write is acknowledged to the app.
- 5Subsequent reads hit the cache and get the fresh, consistent value.
Pair with a read strategy
Write-through only guarantees freshness for data written through it. Cold data still needs to be loaded on read (cache-aside or read-through), and unused fresh entries waste cache space unless you also apply TTLs.
Tradeoffs
- Cache is always consistent with the database.
- No stale reads for written-through data.
- Simpler reasoning than manual invalidation.
- No data loss on cache crash (DB already has it).
- Higher write latency (two synchronous writes).
- Writes to rarely-read data waste cache space.
- Every write incurs cache overhead even if never read.
- Doesn't speed up writes, only guarantees freshness.
Interview Questions
Write-through writes to cache and DB synchronously, so the DB is always current but writes are slower. Write-back writes only to cache and flushes to the DB asynchronously, giving fast writes but risking data loss if the cache crashes before the flush.
It caches every written item regardless of whether it will ever be read. Write-heavy, read-light data fills the cache with entries that provide no read benefit, so it's often combined with TTLs or eviction to reclaim unused space.
- →Writes go to cache and DB synchronously.
- →Cache is always fresh; no stale reads.
- →Higher write latency (two writes per operation).
- →No data loss on cache failure — DB is authoritative.
- →Can waste cache on write-once, never-read data.
Related
Everything on Archprimer is connected — follow the graph.