Write-Through Cache
One-Liner
Writes synchronously update both cache and primary database.
What It Is
A caching strategy where each write operation updates the cache and the underlying data store before returning success.
Why It Exists
- Ensures reads from cache reflect the latest data
- Simplifies read paths
- Reduces staleness-related bugs for read-heavy systems
How It Works
- Client issues a write
- Application writes to cache
- Application writes to database
- Operation succeeds only if both succeed
Tradeoffs
Pros
- Strong consistency for cached reads
- Simple read logic
Cons
- Increased write latency
- Cache becomes part of the write critical path
- Harder failure handling
Failure Modes
- Cache write succeeds, DB write fails → corrupted cache
- Cache outage blocks writes entirely
- Partial failures require rollback or invalidation strategies
Interview Traps
- Claiming “strong consistency” without discussing failure handling
- Ignoring write path latency
- Treating cache as the source of truth
Real-World Usage
Useful in read-heavy systems with strict correctness needs and low write throughput.
Anti-Patterns
- High write-rate systems
- Using write-through when cache reliability is lower than the DB
Related Concepts
- Write-back cache
- Read-through cache