Notesfoundations🌱 seedling
Write-Through Cache
Also: Write-Through · Write-Through Caching
Every write goes to the cache and the backing store together, and is acknowledged only once the store has it. The cache is never behind, at the cost of write latency.
Why it exists
Cache-aside leaves windows where the cache and the database disagree, and a read right after a write may miss. Putting the cache in the write path keeps it current.
How it works
- The app writes to the cache layer, which writes synchronously to the store, then acknowledges.
- Reads after a write hit fresh data.
- Often paired with read-through: the cache, not the app, loads misses from the store.
Trade-offs
| Gains | Costs |
|---|---|
| cache never stale relative to its own writes | every write pays the store's latency |
| simple read-after-write behaviour | caches written data that may never be read |
| no app-side invalidation for writes through it | writes that bypass the cache still leave it stale |
In practice
- DynamoDB Accelerator (DAX): item writes go through DAX to DynamoDB and are cached once DynamoDB confirms them. Writes made directly to DynamoDB bypass it, and DAX stays stale until the TTL.
Pitfalls
- Assuming it makes the cache consistent with everything: only writes that go through it are reflected.
- Filling memory with write-once data; consider write-around for those.
Connections
- Part of
- Caching
- Contrasts with
- Cache-AsideWrite-Back Cache
Recall
These cards are also in your review deck, scheduled with spaced repetition.