Write-Through Caching

Synchronous cache-aware writes that update cache and backing store together to keep read paths fresh.

Write-through caching updates the cache and the backing store in the same write path. The idea is to keep the cache warm and aligned immediately after a write instead of waiting for later reads to repopulate it. This can improve read freshness and reduce invalidation mistakes because the write path explicitly updates cached state.

The cost is that writes now depend on cache coordination as well as store persistence. A write-through design may increase write latency and enlarge the failure surface for writes. If the cache update fails, the system must decide whether to fail the write, retry, or risk divergence.

    sequenceDiagram
	    participant App
	    participant Cache
	    participant Store
	
	    App->>Cache: write(key, value)
	    Cache->>Store: persist(value)
	    Store-->>Cache: success
	    Cache-->>App: success

Why It Matters

Write-through is useful when read freshness right after writes matters and when the system wants to avoid a separate invalidation path for common updates. It is often simpler to reason about than lazy invalidation for some domains because the cache is updated in-band as part of the authoritative write flow.

Where Write-Through Helps

This pattern is attractive when:

  • the same recently written value will likely be read again soon
  • read-after-write freshness matters on the cached path
  • the team wants to keep cache and source aligned in one synchronous workflow

It is less attractive when write latency is already sensitive or when the cache should remain an optional optimization rather than a participant in the write path.

Example

This example models a simple write-through update where cache and store are both part of the successful write contract.

1async function saveProduct(product: Product): Promise<void> {
2  const key = `product:${product.id}`;
3
4  await productStore.save(product);
5  await cache.set(key, JSON.stringify(product), 300);
6}

What to notice:

  • the cache is updated as part of the write path
  • a successful write leaves the cache warm immediately
  • error handling now matters for both store persistence and cache update behavior

A more robust implementation may invert the order or wrap both steps in stronger coordination logic depending on failure semantics. The key point is that the write path owns both persistence and cache freshness.

Common Mistakes

  • assuming write-through is “free consistency” without defining failure handling
  • adding cache participation to latency-sensitive writes without measuring the impact
  • forgetting that cache and store may still diverge on partial failure
  • using write-through when reads are rare and the warmed cache brings little benefit

Design Review Question

What is the main trade-off a team accepts when moving from cache invalidation after writes to write-through updates?

The stronger answer is that the system may get fresher cached reads immediately after writes, but writes now become more coupled to cache behavior and can become slower or more failure-prone if the cache path is unstable.

Quiz Time

Loading quiz…
Revised on Thursday, April 23, 2026