Cache Patterns: Choosing Read and Write Strategies

Compare cache-aside, read-through, write-through, write-around, and write-behind patterns, their freshness trade-offs, and update races to plan for.

published: reading time: 4 min read author: Geek Workbench updated: November 8, 2026
Quick Summary

Cache patterns define who loads a value and how writes update or invalidate the cached copy. This guide compares cache-aside, read-through, write-through, write-around, and write-behind, with a stale-write race to show what each pattern leaves to the application.

Cache Patterns: Choosing Read and Write Strategies

A cache pattern defines who loads a value and how updates reach the cached copy. The pattern affects freshness, latency, and what happens when a source read or write fails. It does not, by itself, guarantee consistency.

Compare the common patterns

Pattern On read On write Main trade-off
Cache-aside The application checks the cache, loads the source on a miss, then stores the result. Usually commit to the source, then invalidate the key. Simple and selective; every write path must invalidate correctly.
Read-through The application reads from the cache, which calls a loader on a miss. Requires a separate update or invalidation rule. Centralizes loading; cache behavior can be less visible to callers.
Write-through Reads use the cache, which is updated as part of the configured write path. The write waits for both cache and source handling. Keeps the cached value current after a successful write, but adds latency and partial-failure handling.
Write-around Reads still populate the cache on misses. Writes bypass the cache and update the source. Avoids filling cache with one-time writes; the first later read misses.
Write-behind Reads use the cache. The cache acknowledges first and persists asynchronously. Can lower write latency, but queue durability, ordering, retries, and recovery become correctness requirements.

Product libraries use some names differently. Confirm the actual ordering and failure behavior before relying on a label.

Which pattern fits?

Use cache-aside when application code should control loading and invalidation. It works well when a small number of known paths read and update the same keys. Use read-through when a cache library can own the loader and callers should not duplicate miss logic.

Write-through can be useful when the application needs the cache updated before a successful write returns. That still does not make the cache and database one atomic system. If either side can fail after the other has changed, define retries, reconciliation, or version checks.

Write-around fits data that is written once and rarely read again, such as a large import that would evict more useful entries. Write-behind is a different choice: the cache accepts a write before the source of truth. Avoid it for data that cannot tolerate loss or reordering unless the write queue is durable and recovery has been tested.

A cache-aside race, step by step

Suppose a request reads a product while an update changes its price:

  1. Request A misses the cache and reads the old product row.
  2. Request B commits the new price and deletes the cache key.
  3. Request A finishes late and stores its old result after the invalidation.
  4. Later readers see the stale price until another invalidation or expiry.

An invalidation after commit is not always enough to prevent this race. If it matters, store a source version with the value and only accept a write when its version is still current, or use versioned keys. An event-based invalidation path should tolerate duplicate delivery and retain a TTL as a backstop.

For a public catalog, a short stale window may be acceptable. For inventory, access control, or price calculation, choose an explicit freshness rule and bypass the cache when that rule cannot be met.

Check before choosing

  • Does every path that changes the source also update or invalidate the cache?
  • Can a late read overwrite a newer value?
  • What should happen if the cache is unavailable?
  • Can users see stale data, and for how long?
  • Does a write need to wait for cache work or durable persistence?
  • Is the cache key scoped by every response-varying input, such as tenant or locale?

Where to go next

Conclusion

Choose the simplest pattern whose write and failure behavior fits the data. Then test the awkward case: an update and a cache miss happening at the same time.

Category

Related Posts

Distributed Caching: Scaling Cache Across Multiple Nodes

Learn how distributed cache clusters route keys, replicate data, recover from node failures, and manage capacity and eviction trade-offs.

#system-design #caching #distributed-systems

Caching Strategies: A Practical Guide

Compare cache-aside, read-through, write-through, and write-behind. See how cache layers, invalidation, freshness goals, and workload shape the choice.

#caching #redis #distributed-systems

Cache Stampede Prevention

Compare cache-stampede controls by the duplicate work they prevent and the failure modes they add, from local single-flight to distributed leases.

#cache #cache-stampede #performance