Write Strategies
Through, back, around.
Reads are only half the story. When a product's price changes, the database and the cache must both know. There are three common strategies for writes.

- Prices change
- Cache and database
- Three strategies
Three write strategies
Write through updates the cache and the database together, so the cache is always fresh, but every write is slower. Write back updates only the cache, and saves to the database later, which is very fast, but risky if the cache crashes. Write around writes only to the database, and lets the cache fill on the next read.
| Strategy | How | Trade-off |
|---|---|---|
| Write-through | cache + DB together | fresh, slower writes |
| Write-back | cache now, DB later | fast, can lose data |
| Write-around | DB only | cache fills on read |
A common recipe
A very common recipe combines two ideas. Read with cache aside. And on a write, update the database, then delete the cached key, rather than updating it. The next read misses, and loads the fresh value. Deleting is simpler and safer than trying to keep the cache exactly in step.
| key | value |
|---|---|
| Reads | cache-aside |
| Writes | update the DB |
| Then | delete the cache key |
| Next read | loads fresh data |
Summary
Write through keeps the cache fresh, write back is fast but risky, and write around skips the cache. A common recipe is update the database, then delete the key. Next, what to throw out when the cache is full.
Key takeaways- Through: fresh
- Back: fast, risky
- Around: lazy