Replication is async — acked writes can vanish
Redis replication is asynchronous primary-backup: writes ack on the master before reaching replicas, so failover can lose acked writes; the backlog buys partial resyncs, WAIT is best-effort, and only min-replicas-to-write converts loss into unavailability.
One node, however well-tuned, is a single point of failure. The first answer is to keep a copy on another node — but that copy lags behind, and that lag is the whole story of this scene.
Scene 06
Replication is async — acked writes can vanish
- Watch
- Try it
- Predict
- Capture
Master accepts writes; the replication backlog ring fills; PSYNC streams keep both replicas' offsets within a tick of the master. This is the steady state — and the trap.
Highlighted lines are the ones running in the diagram right now.
def psync():repl_id, offset = self.replicationId, self.offsetresp = master.PSYNC(repl_id, offset)if resp == CONTINUE:# backlog still covers our gappartial_resync() # stream missed byteselse: # FULLRESYNC <new_id> <new_offset>self.replicationId = resp.new_idfull_resync_via_rdb() # fork + ship RDBstream_replication_link()
def handleWrite(cmd):self.applyToDataset(cmd)self.offset += len(cmd)self.appendToBacklog(cmd)replyOK(client) # ack nowfor r in self.replicas:r.send(cmd) # fire-and-forget
Where this sits in Build Redis
Scene 06 of 10, in the HA act — Replication and Sentinel — async by design.. PSYNC, replication backlog, and the AP-not-CP gotcha: WAIT doesn't fix it; min-replicas-to-write does (at the cost of unavailability).
Up next. Sentinel — replicas keep a copy. But who decides the master is dead, and who promotes a replica into its place?
Designs that use this
- URL ShortenerShorten a long URL. Read-heavy. Don't collide.
- Distributed Rate LimiterEnforce a per-key request limit across a fleet of enforcers — accurately, in under a millisecond, without becoming the outage.
- Twitter / X TimelinePush or pull? Both. The canonical fanout problem.
- Uber / Lyft — Match Drivers and RidersMatch a rider to the closest acceptable driver in under 3 s. Geohash, S2, surge.