Decision guide
Cache-Aside vs Read-Through vs Write-Through vs Write-Behind
Which caching pattern fits this data?
Side by side
| Criterion | Cache-aside | Read-through | Write-through | Write-behind |
|---|---|---|---|---|
| Read latency after a write | One miss | One miss | Fast (already cached) | Fast |
| Risk of stale data | Stale-set race; bounded by TTL | Same as cache-aside | Low for its own writes; other writers still need invalidation | Database lags the cache |
| Risk of data loss | None | None | None | Unflushed writes |
| Write path cost | Database + delete | Database + delete | Database + cache write | Cache only (batched DB writes) |
When to choose each
Cache-aside
The application reads the cache, loads from the database on a miss, and deletes on write.
Choose when
- General-purpose read caching
- Only part of the data is hot
- You want the cache to be optional
Avoid when
- You can't tolerate the stale-set window without leases or versions
Read-through
A cache library or service loads missing entries itself (e.g. Caffeine loaders, DAX).
Choose when
- You want loading logic and coalescing in one place
- In-process caches with loaders
Avoid when
- Complex invalidation across many writers (still needs a pipeline)
Write-through
Writes update the database and then the cache in the same flow.
Choose when
- Data that is read soon after being written
- A single writer path
Avoid when
- Many writers you don't control
- Data rarely read (wastes memory)
Write-behind
Writes go to the cache and are flushed to the database later in batches.
Choose when
- Very high write rates where loss is acceptable or recoverable (views, likes)
- Absorbing bursts
Avoid when
- Money, inventory or anything you can't lose
- When you can't build durable, idempotent flushes
Verdict
Default to cache-aside (or a read-through loader) with delete-after-commit, TTLs and stampede protection. Use write-through for data read right after writing by a single writer, and write-behind only for high-volume, loss-tolerant counters with durable, idempotent flushes.