Quick revision
The short answer
Redis replication is asynchronous: the primary replies OK as soon as it has applied the write, before any replica has received it. If the primary fails in that moment and a replica is promoted, the write was never on the new primary, so it is gone. The window is usually milliseconds of replication lag, but it grows with lag, network trouble and full syncs, and a partitioned primary can keep accepting writes for seconds. WAIT, min-replicas-to-write and the cluster node timeout reduce it, and designing data that must not be lost around a durable store removes the problem.
What to remember
In this answer, we saw that a Redis primary acknowledges writes before its replicas have them, so a failover that promotes a replica loses whatever only the old primary held. The window is usually milliseconds, grows with lag and full syncs, and becomes seconds when a partitioned primary keeps accepting writes. WAIT, min-replicas-to-write with min-replicas-max-lag and the cluster node timeout shrink it, and the dependable answer is to keep data that must not be lost in a durable store and make Redis steps idempotent and rebuildable.
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.
Redis replication is asynchronous: the primary replies OK as soon as it has applied the write, before any replica has received it. If the primary fails in that moment and a replica is promoted, the write was never on the new primary, so it is gone. The window is usually milliseconds of replication lag, but it grows with lag, network trouble and full syncs, and a partitioned primary can keep accepting writes for seconds. WAIT, min-replicas-to-write and the cluster node timeout reduce it, and designing data that must not be lost around a durable store removes the problem.
Why this question is asked
Many developers assume that OK from a database means the data is safe. With Redis it means something narrower: the primary has the write in its memory. Interviewers ask this because the difference explains real incidents, from lost cart items to duplicate payments, and because the answer shows whether we understand replication and failover rather than just using them. In this answer, we will recap how Redis replicates, follow a write that gets lost, see how large the window can grow, and then look at the settings that shrink it and the design rule that makes it harmless.
1A Quick Recap of Redis Replication and Failover
A Redis primary handles writes, and replicas keep copies. The primary sends every write command to its replicas over a replication stream, and each replica tracks how far it has read with a number called the replication offset. A replica that is a few commands behind has a smaller offset than the primary.
Failover is what happens when the primary dies. With Sentinel, a group of separate Sentinel processes agrees that the primary is down and promotes one replica. With Redis Cluster, the replicas of the failed primary hold an election among the cluster's primaries. Either way, the promoted replica becomes the new truth, and whatever it had not received no longer exists.
2Following a Write That Disappears
The key detail is the order of events on the primary. It executes the write, replies OK to the client, and sends the command to the replicas, but it does not wait for them. In normal conditions the replicas receive it within a millisecond, so we never notice.
7 messages in order. Play them, or step through them one at a time.
The client was told OK, but the only copy died with the old primary.
So the client did nothing wrong, and Redis did nothing wrong either. It behaved exactly as an asynchronous system does: acknowledging before replicating trades a small risk of loss for very low latency.
3How Large the Window Is
Normally the window is the replication lag, a millisecond or less on a healthy network. Several things make it larger. A replica that falls behind under heavy write load, a slow network link between zones, or a full resynchronisation, when a replica reloads the whole dataset and is far behind until it catches up, all increase the amount of data only the primary has.
The worst case is a network partition. If the primary is cut off from Sentinel and its replicas but some clients can still reach it, it does not know that it is about to be replaced. It keeps accepting their writes while the other side promotes a replica. When the partition heals, the old primary becomes a replica of the new one, resyncs, and throws away everything it accepted in the meantime. That can be many seconds of writes.
4What Shrinks the Window
WAIT numreplicas timeout makes the client wait until that many replicas have acknowledged all of its earlier writes, or until the timeout. It lowers the chance of loss for that write, but it is not a strong guarantee: failover may still promote a replica that was not one of those that acknowledged, and if WAIT times out, the write is still on the primary, nothing is rolled back.
For partitions, min-replicas-to-write and min-replicas-max-lag make an isolated primary stop accepting writes. With min-replicas-to-write 1 and min-replicas-max-lag 10, the primary refuses writes with a NOREPLICAS error once it has had no replica acknowledging within 10 seconds. In Redis Cluster, a primary on the minority side of a partition stops accepting writes after cluster-node-timeout, because it can no longer reach the majority of primaries.
Notice that these settings bound the loss rather than remove it: an isolated primary can still accept writes for up to about 10 seconds before it notices.
5Designing for Loss
Because the window can be shrunk but not closed, the reliable fix is a design rule. Data that must not be lost lives in a durable system of record, such as a database table written in a transaction. Redis holds copies, caches and fast pre-checks that can be rebuilt from that record. Steps that use Redis are idempotent, meaning that running them twice has the same effect as once, so a retry after a lost write does no harm.
For a cart, that may mean writing cart changes to the database and caching them in Redis. For a counter used only for analytics, losing a second of increments is fine, and Redis alone is acceptable. The decision is per use, based on what losing a few seconds of writes would cost.
6Follow-up questions
Why does Sentinel prefer the replica with the largest offset?
Because the replication offset tells how much of the primary's stream each replica has received, the replica with the largest offset has the most recent data, so promoting it loses the fewest writes. Sentinel first excludes unsuitable replicas, such as those disconnected for too long, then sorts by replica-priority, then by the largest offset, and finally by the smallest run ID as a tie-breaker. Redis Cluster does something similar: replicas with larger offsets start their election sooner, so they usually win.
Does AOF with appendfsync always prevent this loss?
No. AOF protects one node's data against restarts. In a failover the old primary's disk is not used at all; the promoted replica's data becomes the truth. Only replication-related settings, and a durable system of record, address failover loss.
Is WAIT the same as synchronous replication?
Not really. It waits for acknowledgements, but there is no agreement protocol that ensures the promoted replica is one that acknowledged, and no rollback when the timeout passes. It is best described as making loss less likely for chosen writes.
7Conclusion
In this answer, we saw that a Redis primary acknowledges writes before its replicas have them, so a failover that promotes a replica loses whatever only the old primary held. The window is usually milliseconds, grows with lag and full syncs, and becomes seconds when a partitioned primary keeps accepting writes. WAIT, min-replicas-to-write with min-replicas-max-lag and the cluster node timeout shrink it, and the dependable answer is to keep data that must not be lost in a durable store and make Redis steps idempotent and rebuildable.
Open with
Redis replication is asynchronous. The primary applies the write and replies OK to the client, and only then streams it to the replicas without waiting for them. If the primary dies in that gap and Sentinel or the cluster promotes a replica, the write was never on the new primary, so it is lost even though the client was told OK.
Then, if they want more
Normally the window is the replication lag, a millisecond or so, but it grows when replicas lag under load, when the network between zones is slow, or during a full resync.
The worst case is a partition: the old primary can keep accepting writes from clients on its side until it notices it is isolated, and when it rejoins as a replica, those writes are discarded.
To shrink it, WAIT makes a client wait until a number of replicas acknowledge its earlier writes, which helps for important writes but is not a strong guarantee. min-replicas-to-write with min-replicas-max-lag makes an isolated primary refuse writes after the lag limit, and in Cluster a minority-side primary stops writes after cluster-node-timeout.
But the real fix is design: data that must not be lost lives in a durable system of record, and anything using Redis is idempotent and can be rebuilt.
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 documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Redis documentation
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 "Why can an acknowledged write disappear after a failover with Sentinel or Redis Cluster...": https://scrivio-interview-library.netlify.app/databases/redis-scaling/8d62f1044f/