Write Policy

Quick Reference: Cache | Replacement Policy


Quick Reference

Write PolicyWrite to CacheWrite to DBProsCons
Write-ThroughImmediatelyImmediatelyConsistent, simpleSlower writes
Write-BehindImmediatelyAsyncFast writesRisk of data loss
Write-AroundSkipImmediatelyCache not pollutedCache miss on read
Write-InvalidateInvalidateImmediatelySimpleCache 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

  1. Choose Based on Requirements: Consistency vs performance
  2. Handle Failures: Plan for cache/DB failures
  3. 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