Home/Labs/Write-Through Latency Trade-offs
All 280 Labs
INTERACTIVE LAB✍️

Write-Through Caching Lab (Interactive)

Tune write rate, commit latency, and unread-write share to compare Write-Through and Cache-Aside second by second. Quantify the Write-Through bargain: synchronous RAM+disk dual writes buy zero read misses on fresh data, at higher write latency and wasted RAM.

Write-Through vs Cache-Aside Trade-off Lab

Pay the synchronous RAM+DB dual write on every PUT — and collect zero read misses on freshly written data.

Workload Inputs

readQps = 10,000/s · total = 12,000/s
Metric
Write-Through
Cache-Aside
Write latency
15.2 ms
15.1 ms ✓
Avg read latency
0.50 ms ✓
2.78 ms
Read misses /s on fresh data
0 (always warm) ✓
1500/s
RAM wasted on unread writes
49.4 GB/day
≈0 GB (lazy only) ✓
Blended system latency
2.95 ms ✓
4.83 ms
Dual-persistence math
WT WRITE = RAM 0.2ms + sync DB 15ms = 15.2 ms (ack only after both confirm)
CA WRITE = DB 15ms + DEL 0.1ms = 15.1 ms, but a fresh entity's first read = GET nil + SELECT + SET
WT COLD RAM = 2,000/s × 15% × 2048B × 86,400 = 49.4 GB/day needing LRU + TTL eviction
With 15% unread writes, Write-Through wins: chat messages and notifications are read seconds after being written, so eliminating fresh-read misses (2.95 ms blended vs 4.83 ms) justifies the 15ms synchronous DB hop.

Interview line: “Write-Through trades +15ms of write latency for zero read misses on new data — right for Discord-style hot channels, wrong for telemetry ingestion.”

How It Works Under the Hood

Write-Through makes the cache the application’s only interface: the provider updates RAM, then synchronously persists to the database, acknowledging only after both confirm. Every write pays RAM + disk commit (~0.2 + 15ms), but newly written entities are guaranteed warm, so read cold-starts vanish — ideal when data is read seconds after creation, like Discord or Slack channel messages. The hazard is memory pollution: writes that are never read (audit logs, telemetry) still enter RAM and, via LRU, evict genuinely hot items, which is why Write-Through must be paired with aggressive TTLs and eviction policies.

Core Architectural Principles

  • Write latency = RAM write + synchronous DB commit; success is acknowledged only after both.
  • Zero read misses on newly written data — the cache is always the freshest system of record view.
  • Cold writes that are never read still consume RAM and evict hot keys without LRU + TTL safeguards.
Interview Round Script

Contrast Write-Through with Cache-Aside along two axes: write latency (higher, dual synchronous write) versus read freshness (zero misses on new data). Recommend it for chat channels, collaborative documents, and notifications — anything written then immediately read. Pair the answer with the memory caveat: run LRU eviction and TTLs so write-once-never-read records cannot exhaust the cache.

Key Trade-Offs

Always-fresh cached reads and simpler application code in exchange for slower writes and RAM spent on data that may never be read.

Related Curriculum Chapter

Write-Through Caching

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs