Problem
Cache-aside leaves stale windows and forces every caller to manage invalidation, while direct database writes are slow under heavy write load. Teams need either always-fresh caches or faster write acknowledgement.
Also known as: write-through-cache, write-back-cache, write-behind
Keep a cache synchronized with the store by writing through it, either synchronously or asynchronously.
Cache-aside leaves stale windows and forces every caller to manage invalidation, while direct database writes are slow under heavy write load. Teams need either always-fresh caches or faster write acknowledgement.
These two patterns place the cache in the write path. They differ in when the database learns about a write: before the acknowledgement (write-through) or after it (write-behind).
Write-through:
client -> cache -> database -> ack -> client
Write-behind:
client -> cache -> ack -> client
\-> queue -> batch flush -> database
With write-through, the application or a caching library writes to the store, then updates the cache entry. Failure of the database write fails the whole operation, so cache and store agree. The cost is that write latency is the sum of both hops.
With write-behind, the cache holds the newest value and a dirty-set. A background flusher writes dirty keys in batches, often every few hundred milliseconds. If a key is updated ten times between flushes, only the final value reaches the database, which is ideal for counters, presence and last-seen timestamps.
Cache cluster plus durable queue for write-behind
Medium: monitor flush lag and failures
High: failure semantics are subtle
Cache node dies with unflushed writes, losing acknowledged data
Flush backlog grows until memory is exhausted
Database rejects a flushed write after the client was told it succeeded