Video in progress
What does it mean in practice that Redis replication is asynchronous, and which writes can be lost when the master goes down?
The master returns OK to the client without waiting for the replicas to receive the write. If the master crashes in the meantime and a replica is promoted, the latest writes that hadn't reached it are lost for good. WAIT reduces this but doesn't fully guarantee it.
📖 Answer
The sequence:
1. client: SET balance:7 500 -> master OK
2. master added it to the replication stream, hasn't sent it yet
3. master crashes
4. Sentinel promotes a replica -> balance:7 has the old value
What the client considered written is now gone. This is a deliberate Redis trade-off, made for speed.
What you can do:
SET balance:7 500
WAIT 1 100 # waits up to 100 ms for at least 1 replica to acknowledge
The number WAIT returns is how many replicas acknowledged. But even this isn't "synchronous replication": the replica has the write in RAM, not on disk, and on failover a different, lagging replica may be chosen.
min-replicas-to-write 1
min-replicas-max-lag 10
This setting stops writes when the master is cut off from its replicas. It narrows the window for writes that go to the "old" master during a network split and are later discarded.
For the same reason, reading from a replica can return stale data (read-your-writes breaks). My conclusion: if a write in Redis must not be lost, the source of truth should be somewhere else.
Sign up to mark studied questions and save your progress.