Quick revision
The short answer
With write-behind (write-back), the application writes to the cache, which acknowledges at once and saves to the database later, often batched and coalesced, so writes are fast and the database sees fewer of them; the risk is that queued writes are lost if the cache node fails and that the database lags behind. With write-around, writes go only to the database and the cache fills on later reads, which keeps rarely read data out of the cache at the cost of a miss on the first read after a write. Write-behind fits frequent, loss-tolerant updates like view counters, and write-around fits write-heavy, rarely re-read data like logs and uploads.
What to remember
In this answer, we saw that write-behind acknowledges writes from the cache and saves them to the database later, batched and coalesced, which makes writes fast and cuts database load but risks losing queued writes and leaves the database behind. Write-around sends writes only to the database and fills the cache on reads, which keeps unread data out of the cache at the cost of a first-read miss. Write-behind suits frequent, loss-tolerant updates like counters, write-around suits write-heavy, rarely read data like logs, and grids such as Hazelcast and Redisson provide write-behind while plain Redis needs our own queue and flusher.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
With write-behind (write-back), the application writes to the cache, which acknowledges at once and saves to the database later, often batched and coalesced, so writes are fast and the database sees fewer of them; the risk is that queued writes are lost if the cache node fails and that the database lags behind. With write-around, writes go only to the database and the cache fills on later reads, which keeps rarely read data out of the cache at the cost of a miss on the first read after a write. Write-behind fits frequent, loss-tolerant updates like view counters, and write-around fits write-heavy, rarely re-read data like logs and uploads.
Why this question is asked
Most caching discussions stop at reads, but every cache design also has to answer what happens on a write. The choice decides how fast writes are, how fresh the database is, and what can be lost in a crash. Interviewers ask about write-behind and write-around because they sit at opposite ends: one puts the cache in front of every write, the other keeps writes away from it entirely. In this answer, we will recap the write policies, explain write-behind and its risks, explain write-around and its cost, match each to use cases, and see which tools provide them.
1A Quick Recap of Cache Write Policies
A write policy says how a write reaches the cache and the database. With cache-aside, the application writes the database and then deletes or updates the cache entry. With write-through, the application writes to the cache, and the cache writes to the database synchronously before it acknowledges, so both are always in step. The two policies in this question change the timing: write-behind delays the database write, and write-around skips the cache.
| Policy | Write goes to | Acknowledged after | Database is |
|---|---|---|---|
| Cache-aside | database, then cache delete | database commit | current |
| Write-through | cache, which writes database | both written | current |
| Write-behind | cache; database later | cache write only | behind by the queue |
| Write-around | database only | database commit | current; cache filled on read |
2How Write-Behind Works
In write-behind, also called write-back, the application writes to the cache, and the cache acknowledges immediately. The cache puts the change in a queue, and a background writer saves queued changes to the database later, for example every few seconds. Two optimisations make this attractive. Batching sends many changes in one database round trip. Coalescing keeps only the latest value for each key, so a counter updated 1,000 times in five seconds becomes one database write.
So the application sees cache-speed writes, and the database sees a fraction of the write volume. That is the whole point of write-behind.
3What Write-Behind Risks
The first risk is durability. Between the acknowledgement and the database write, the change exists only in the cache's queue. If the cache node crashes or loses power, or is restarted during a deployment, the queued changes are gone, even though the application was told they succeeded. Replicating the queue to another node reduces this but does not remove it.
The second risk is freshness. The database is always somewhat behind, by the queue's delay or much more during a database outage. Anything that reads the database directly, such as reports, other services or analytics, sees old data. And ordering and retries need care: if a write fails and is retried after a newer write for the same key, the older value can overwrite the newer one unless writes are coalesced per key and applied in order, or made conditional on a version.
4How Write-Around Works
In write-around, writes go straight to the database and do not touch the cache, except to delete a stale entry if one exists. The cache is filled only when the data is read, typically with cache-aside reads: a read misses, loads from the database and stores the value.
5 messages in order. Play them, or step through them one at a time.
Data that is never read never takes up cache memory.
The benefit is that data nobody reads never enters the cache, so the cache's memory holds what is actually read. The cost is that the first read after a write is always a miss and pays the database latency. Writes themselves are as durable and current as the database makes them, because the cache is not involved.
5Choosing a Use Case for Each
Write-behind fits data that is updated very frequently and where losing a few seconds of updates is acceptable: view and like counters, last-seen timestamps, game scores in a casual game, metrics aggregates. In each case, losing the last five seconds after a rare crash is a small inaccuracy, and the reduced database load is large.
Write-around fits data that is written often and read rarely or much later: log and audit entries, uploaded files and their metadata, event history, bulk imports. Caching these on write would fill the cache with entries that are evicted before anyone reads them, pushing out the data that is actually hot.
6Which Tools Provide Them
Write-behind needs a component that owns the queue and the background writer. Data grids provide it: Hazelcast does write-behind when a MapStore is configured with a write delay greater than zero, with coalescing and batching options, and Redisson offers a map writer in write-behind mode for its Redis-backed maps; the exact configuration classes differ between versions, so check yours. With plain Redis, there is no built-in database writer, so we build the queue and the flusher ourselves, for example by recording changed keys in a set or a stream and running a worker that reads and saves them in batches.
Write-around needs no special support at all: it is simply writing to the database and using cache-aside for reads, which Spring's @Cacheable with @CacheEvict on writes already gives us.
7Follow-up questions
Why is write-around usually combined with cache-aside reads?
Because write-around only says what writes do; something still has to put data into the cache, and since writes do not, reads must. Cache-aside does exactly that: a read misses, loads from the database and stores the value. The write path then only needs to delete any existing entry for the key, so a later read does not see an old cached copy. Together they give a cache that holds only data that has been read, and a database that is always current.
Is write-behind the same as an asynchronous message to the database?
Conceptually close. The difference is that the cache serves reads of the new value immediately and coalesces many updates per key, while a message queue usually delivers every change. Putting a durable log such as Kafka between the cache and the database is a common way to remove write-behind's durability risk.
Can write-behind and write-through be mixed?
Yes, per data type. A grid can use write-through for orders, which must never be lost, and write-behind for view counters on the same cluster, since the policy is configured per map.
8Conclusion
In this answer, we saw that write-behind acknowledges writes from the cache and saves them to the database later, batched and coalesced, which makes writes fast and cuts database load but risks losing queued writes and leaves the database behind. Write-around sends writes only to the database and fills the cache on reads, which keeps unread data out of the cache at the cost of a first-read miss. Write-behind suits frequent, loss-tolerant updates like counters, write-around suits write-heavy, rarely read data like logs, and grids such as Hazelcast and Redisson provide write-behind while plain Redis needs our own queue and flusher.
Open with
Write-behind, also called write-back, means the application writes to the cache, the cache acknowledges right away, and a background writer saves the change to the database later, usually batched and coalesced, so a counter updated a thousand times in five seconds becomes one database write.
Then, if they want more
Writes are fast and the database sees far fewer of them. The risks are durability and freshness: queued writes are lost if the cache node fails before flushing, and the database lags behind, so reports and other readers of the database see old data. Ordering and retries need care too, or an older value can overwrite a newer one.
Write-around is the opposite: writes go only to the database, and the cache is filled on later reads, usually with cache-aside. That keeps data nobody reads out of the cache, but the first read after a write is always a miss.
So I would use write-behind for frequent updates where losing a few seconds is acceptable, like view counters or last-seen times, and write-around for write-heavy, rarely re-read data like logs, uploads or audit entries. Data grids provide write-behind, for example Hazelcast with a MapStore and a write delay, or Redisson's map writer in write-behind mode. With plain Redis I would build the queue and the flusher myself.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain write-behind and write-around, what each one risks, and give a fitting use case...": https://scrivio-interview-library.netlify.app/architecture/caching-strategies/c97e1f97b9/