Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk6 min

Cache Invalidation: Three Patterns and the Cost of Getting It Wrong

Cache-aside, write-through, and write-behind place consistency work in different parts of an application. Compare their stale-data risks, failure modes, and trade-offs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cache invalidation is the work of keeping cached values from being served after their authoritative data changes. The practical choice is usually between cache-aside with invalidation, write-through, and write-behind: each puts work in a different part of the read or write path and creates a different failure window. None is universally best; the right fit depends on how stale data may be, how the application reads and writes, and what happens if a write is delayed or lost.

What cache invalidation means

A cache stores copies of data so an application can serve repeat reads without consulting its primary data store every time. When the primary changes, the cached copy may no longer be correct. Cache invalidation is the action that makes that old copy unavailable or replaces it, so later reads can obtain a current value.

As an Amazon Associate I earn from qualifying purchases.

With cache-aside, a common invalidation action is to delete the affected key after a successful primary-store update. Redis describes the sequence this way: “When a write hits the primary, the application invalidates the cache key. The next read pulls fresh data from the primary.” Redis’s cache-aside implementation guide demonstrates this pattern; it is an implementation description, not a guarantee of immediate consistency across every distributed system.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How the three patterns differ

Pattern Read and write behavior Main advantage Main cost or failure mode
Cache-aside with invalidation Reads check the cache and load the primary on a miss. Writes update the primary and delete the cached key. Only requested data needs to enter the cache; the flow is straightforward. Misses add latency and primary load. Missed invalidations or refill races can leave stale data; concurrent misses can stampede.
Write-through A write updates the primary and cache synchronously. Readers are more likely to find the updated value in cache after a write. Writes do more work; a partial failure can leave the stores inconsistent, and rarely read data may consume cache space.
Write-behind The cache accepts the write, then persists it to the primary asynchronously. Can absorb bursts and reduce immediate write pressure on the primary. Persistence and visibility are delayed; writes not yet flushed can be lost if the cache fails.

AWS’s caching-pattern guidance describes cache-aside and write-through, including the initial miss cost of cache-aside and greater cache use with write-through. Redis discusses write-behind as a throughput trade-off that weakens consistency and can expose unflushed data to loss.

Cache-aside with invalidation: load on demand, delete after writes

On a read, the application looks up the key in cache. If it is present, the application returns that value. If it is absent, the application reads the primary, stores the result in cache, and returns it. On a write, the application updates the primary and then deletes the corresponding cached key. The next cache miss reloads from the primary.

This avoids preloading or caching every record, but correctness depends on invalidation reaching the right key after changes. If an update commits but deletion fails or is skipped, a reader can continue receiving the old cached value until another invalidation or its expiration. A database change made by another service, job, or administrator can bypass application-managed invalidation entirely.

Write-through: update both stores on the write path

In write-through, the application updates the primary and the cache synchronously as part of handling a write. This adds work and latency to writes, but can make the new value available in cache immediately after the operation succeeds, which is useful when read-after-write behavior matters.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“Both” does not mean “atomic.” If one store accepts the change and the other fails, the application has to decide how to retry, reconcile, or report the result. Write-through can also fill the cache with values that are written but rarely read.

Write-behind: acknowledge first, persist later

Write-behind accepts a change in the cache and sends it to the primary later. This can smooth bursts of writes, but a caller may observe an acknowledged value that has not yet reached durable primary storage. If the cache fails before the pending change is flushed, that change may be lost. Use this pattern only when delayed persistence and its loss window are acceptable for the data.

What goes wrong when invalidation is mishandled

Stale reads after an update

If the application updates the primary but leaves the old cache entry in place, subsequent reads may return that old value. Expiration can eventually remove it if a TTL is configured, but until then staleness remains possible. Application-only invalidation is also incomplete when other writers modify the primary without notifying the application that owns the cache.

A cache-fill race can put old data back

Consider a read that misses the cache and fetches an old value from the primary. Before that request caches its result, another operation updates the primary and deletes the key. If the first request then stores its old result, the cache once again contains stale data. This race is not inevitable in every implementation, but it must be addressed where it can occur—for example, by coordinating fills and writes or using a version-aware strategy.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Partial write-through failure splits the stores

A synchronous write to two stores can fail partway through: the primary may accept the new value while the cache does not, or vice versa. Retry and reconciliation behavior should be explicit, rather than assuming the two updates form one transaction.

Write-behind can lose unflushed changes

With asynchronous persistence, the cache temporarily holds changes that the primary has not yet recorded. A cache failure during that interval can erase pending writes. The acceptable risk depends on the data’s durability requirements, not just on throughput goals.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

TTL helps bound exposure but does not ensure consistency

A time-to-live (TTL) expires an entry after a configured period. For cache-aside, a TTL limits how long an entry can remain available without a refresh, but it does not make a stale read impossible before expiry, coordinate multiple stores, or ensure that every reader sees the latest primary value. Redis’s cache-aside guidance covers TTL alongside explicit invalidation.

A longer TTL can improve cache reuse while extending the period in which an outdated value may be served. A shorter TTL reduces that potential exposure but creates more misses and more requests to the primary. Choose the duration against the application’s staleness tolerance and read pattern. When a change cannot wait for expiry, explicit invalidation or another coordinated update mechanism is needed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Expiration can trigger a cache stampede

When a popular key expires, many callers may miss at nearly the same time and all request the same value from the primary. The resulting burst of redundant reads can overload the source just when demand is concentrated. A single-flight mechanism, lock-based loading, or an appropriate refresh strategy can coordinate refills so callers do not all perform the same work. A TTL alone does not prevent a stampede.

Choose a pattern by workload and failure tolerance

  • Read-heavy, with some staleness acceptable: cache-aside with a TTL is a reasonable starting point. Add invalidation after writes when readers need fresher values.
  • Read-after-write behavior is important: consider synchronous write-through, and define what the application does when one store succeeds and the other does not.
  • Write-heavy, recoverable or low-risk data: write-behind may absorb bursts if delayed persistence and possible loss before flush are acceptable.
  • Other services or operators also write the primary: application-only invalidation will miss those changes. Add a change-event or other coordination mechanism, with expiration as a backstop.
  • Popular keys expire under concurrent traffic: coordinate cache fills with single-flight, locking, or a suitable refresh approach.

Compare the options against the properties that matter to the application: tolerated staleness, write latency, cache memory use, behavior after partial failures, refill load, and durability. The trade-offs are workload-dependent; the descriptions in Redis’s cache-consistency overview and Redis’s caching-at-scale paper provide further context on invalidation, races, and consistency choices.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.