TOPIC #99Intermediate 7 min read

Write-Through Caching

CSD
CompleteSystemDesign Editorial
Report an issue
Key takeawayCore Architecture Summary

Achieve tight cache-database consistency: Synchronous inline writes, cache as system-of-record, and read-latency optimization.

Key Glossary Concepts in this TopicAll Glossary Terms
Interactive Lab · ✍️ Write-Through Latency Trade-offsFull lab guide

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.”

Write-Through Cache Flow ✍️

Application writes to the cache layer, which synchronously updates the database.

Write-Through Cache Flow ✍️
100%
Touchpad: Pinch to zoom • Drag to pan
Rendering visual architecture flowchart...

01.How Write-Through Caching Works

In the Write-Through Caching pattern, the cache acts as the direct system of record from the application's perspective. The application never communicates directly with the primary database; all read and write operations pass through the caching abstraction layer.

The Write Pipeline:

  1. The application executes a write command to the cache provider: cache.set(key, value).
  2. The cache synchronously updates its in-memory storage.
  3. The cache immediately persists the update to the underlying relational/NoSQL database in the same synchronous operation.
  4. The cache returns success to the application only after both in-memory RAM and persistent disk storage have confirmed the write.

The Immediate Read Benefit:

Because every write immediately populates the cache before returning, subsequent read requests for newly created or updated entities are guaranteed to be 100% cache hits, completely eliminating read cold-starts.

02.Write-Through vs Cache-Aside: Key Differences

DimensionWrite-Through CachingCache-Aside (Lazy Loading)
Who Writes to DB?The Cache Layer abstraction automatically persists to DB.The Application Code manually orchestrates DB and Cache.
Write LatencyHigher: Incurs latency of (RAM Write + Disk DB Write).Lower: Only writes to DB, then deletes cache key.
Read Latency (New Data)Zero Misses: New data is immediately in RAM upon creation.Cache Miss: Initial read must fetch from DB and populate cache.
Memory UtilizationLower Efficiency: Caches all written data, even if never read again.High Efficiency: Caches only data that clients explicitly read.
Data StalenessExtremely low; cache and database are tightly coupled.Minimal if properly invalidated, but requires careful app logic.

03.Real-World Use Cases & Memory Safeguards

Because Write-Through populates memory for every write, writing large volumes of data that are rarely read (e.g., archived audit logs or telemetry records) will rapidly consume RAM and cause premature cache eviction of hot items.

Best Practices:

  • Pair with TTL & LRU Policies: Always configure aggressive Least Recently Used (LRU) eviction and Time-To-Live (TTL) expiration so that write-through entities that are not read within a set window (e.g., 2 hours) are cleanly evicted from RAM.
  • Ideal Workloads: Messaging applications (Slack, Discord active channels), live sports commentary, and user presence state, where new messages are written and immediately read by thousands of subscribers within seconds.

Architectural Trade-offs & Production Realities

Architectural Advantages

  • Guarantees cache is always completely fresh with zero read cache misses for newly created items
  • Simplifies application code by abstracting database interactions behind a unified cache client

Trade-offs & Constraints

  • Increases write latency because every write requires two synchronous hops (RAM write + DB disk commit)
  • Can waste expensive RAM caching data that is written once and never read again
Production Implementation in Big Tech
Discord• Active Channel Message Buffering

Discord keeps recent channel messages cached in memory while synchronously writing to ScyllaDB so other channel members immediately see messages with zero cache miss lag.

Staff+ Engineering Takeaways

  • Write-Through updates both cache and DB synchronously on every write.
  • Eliminates read cache misses for newly written records.
  • Increases write latency due to two synchronous writes.
  • Requires LRU and TTL eviction policies to prevent memory pollution.

Topic Knowledge Check

Exercise 1 of 1 • Test your architectural comprehension.

Exercise 1 of 10 answered
1

What is the primary trade-off of the Write-Through caching pattern?

Rate This Architecture ChapterFeedback & Rating

How clear and actionable was this distributed systems breakdown?

Interactive Engineering Workbenches: