Write Policy
Quick Reference: Cache | Replacement Policy
Quick Reference
| Write Policy | Write to Cache | Write to DB | Pros | Cons |
|---|---|---|---|---|
| Write-Through | Immediately | Immediately | Consistent, simple | Slower writes |
| Write-Behind | Immediately | Async | Fast writes | Risk of data loss |
| Write-Around | Skip | Immediately | Cache not polluted | Cache miss on read |
| Write-Invalidate | Invalidate | Immediately | Simple | Cache miss on read |
Clear Definition
Write Policy determines how writes are handled when updating cached data. Different policies balance between consistency, performance, and complexity.
š” Key Insight: Choose write policy based on consistency requirements and performance needs.
Core Concepts
Write-Through
How it Works: Write to cache and database simultaneously.
Pros: Consistent data, simple logic
Cons: Slower writes (waits for DB)
Use Cases: When consistency critical
Write-Behind (Write-Back)
How it Works: Write to cache immediately, write to DB asynchronously.
Pros: Fast writes, better performance
Cons: Risk of data loss if cache fails
Use Cases: High write throughput, can tolerate some data loss
Write-Around
How it Works: Write directly to DB, skip cache.
Pros: Cache not polluted with write-only data
Cons: Cache miss on subsequent read
Use Cases: Write-heavy, read-rarely data
Best Practices
- Choose Based on Requirements: Consistency vs performance
- Handle Failures: Plan for cache/DB failures
- Monitor: Track write performance and consistency
Quick Reference Summary
Write-Through: Write to both cache and DB. Consistent but slower.
Write-Behind: Write to cache, async to DB. Fast but risky.
Write-Around: Write to DB only. Good for write-heavy data.
Previous Topic: Cache ā
Next Topic: Replacement Policy ā
Back to: Step 4 Overview | Main Index