Pattern
Write-through cache
Problem
In cache-aside, cache and DB can diverge briefly on writes. You need stronger cache-consistency.
Context
You have a read-heavy workload but occasional writes must be immediately visible in the cache.
Solution
Writes go to the cache first, and the cache synchronously writes to the DB before ACKing. Reads always hit cache (or on miss, fall through). Cache and DB stay in sync — at the cost of every write paying both round-trips.
Trade-offs
- Every write pays cache-write + DB-write latency
- Write path is coupled to cache availability — if cache is down, writes fail
- Cache holds data that may never be read (waste of memory)
Failure modes
- Cache down → writes fail (unless you fall through, which loses the sync guarantee)
- Partial write success (cache OK, DB fail) causes divergence — needs transaction wrapping
When to use
- Read-heavy with immediate-visibility writes needed
- Cache is highly available and colocated with the app
When NOT to use
- Write-heavy workload
- You can tolerate stale reads for a few seconds