caching
Write-Through / Write-Back
Compare synchronous vs deferred write strategies for cache consistency
ModeThrough
Cache Keys0
DB Keys0
Dirty Keys0
App
WRITE
→
Cache
always ✓
→sync
Database
sync ✓
// cache
empty
// database
empty
// event log
No events yet.
// write-through
- Writes go to both cache and DB synchronously
- Strong consistency — DB always up-to-date
- Higher write latency (waits for DB)
// write-back
- Writes go to cache only; DB updated later
- Much lower write latency
- Risk of data loss if cache crashes
- DB temporarily inconsistent (dirty keys)