Scrivio Interview library
ConceptFoundations6 min read · updated 13 November 2026

A Redis primary with two replicas serves a Spring Boot service. Replication is what lets replicas take over after a failure and serve reads, so it pays to know exactly what a replica receives and when.

How does Redis replication work from the moment a replica connects, what are the replication ID, the offset and the backlog for, and when does a replica need a full resynchronisation instead of a partial one?

Redis replication is asynchronous: the primary answers the client and then streams the same writes to each replica, which acknowledges its offset about once a second. A reconnecting replica sends PSYNC with the replication ID and offset it last saw, and if the primary recognises the ID and still has that offset in its replication backlog, it sends only the missing bytes. Otherwise the replica needs a full sync from an RDB snapshot.

Why this question is asked

Replication is the base of everything else in Redis high availability: Sentinel promotes replicas, Redis Cluster fails over to them, and Spring services read from them. Knowing exactly what a replica receives, and when it has to start from scratch, explains many production surprises, from lost writes after a failover to replicas that never catch up. Interviewers ask this question because the replication ID, the offset and the backlog are simple ideas that people often mix up. In this answer, we will recap the moving parts, follow a replica from its first connection, see when partial sync works and when it cannot, look at failover and restarts, and finish with how replicas treat expiring keys.

1A Quick Recap: Replication ID, Offset and Backlog

Every primary has a replication ID, a random 40-character string that names one history of its dataset. Alongside it is the replication offset, a byte counter that grows with every byte of the write stream the primary sends to replicas. The pair (ID, offset) identifies an exact point in that history, much like a commit in version control.

The replication backlog is a fixed-size ring buffer on the primary holding the most recent bytes of the write stream, 1 MB by default (repl-backlog-size). Its job is to let a replica that briefly disconnected catch up from where it stopped, without copying the whole dataset again.

Shell
redis-cli INFO replication # on the primary
# role:master
# connected_slaves:2
# slave0:ip=10.0.1.12,port=6379,state=online,offset=88412391,lag=0
# master_replid:3f9c1b...e27a the current history
# master_replid2:0000000000...0000 secondary ID, set after a promotion
# master_repl_offset:88412391 bytes of write stream so far
# repl_backlog_size:1048576 1 MB ring buffer

2The Steady State: Asynchronous Streaming

When a client sends SET cart:42 x, the primary applies it, replies OK to the client, and then appends the command to the stream it sends to every replica and to the backlog. The client does not wait for any replica. That is why replication is called asynchronous, and why a write acknowledged to a client can be lost if the primary fails before the bytes reach a replica.

Each replica applies the stream in order and, about once per second, sends REPLCONF ACK with the offset it has processed. The primary uses these acknowledgements to show lag in INFO, and to support WAIT, which lets a client block until a given number of replicas have acknowledged its writes when it needs stronger confirmation.

3Connecting: Partial or Full Synchronisation

When a replica connects, or reconnects after a drop, it sends PSYNC with the replication ID and the offset it last processed. A brand-new replica has neither and sends PSYNC ? -1. The primary then makes one decision.

Step throughHow the primary answers PSYNC
  1. Replica sends PSYNC <replid> <offset>PSYNC ? -1 if it has no history
  2. Is replid the primary's current or secondary ID?
    YesCheck the offsetNoFull sync
  3. Is the offset still inside the backlog?
    Yes+CONTINUE: send only the missing bytesNoFull sync
  4. Full sync: +FULLRESYNC <replid> <offset>primary creates an RDB snapshot
  5. Writes during the snapshot go to the replica's output buffer
  6. Replica loads the RDB, then receives the buffered writesback in steady state

6 steps in order. Play them, or step through them one at a time.

A partial sync is cheap: if the replica was disconnected for 2 seconds and missed 300 KB of writes, the primary sends those 300 KB from the backlog. A full sync is expensive: the primary forks a child process to produce an RDB snapshot of the whole dataset, either written to disk and then sent, or streamed straight to the socket with diskless sync (repl-diskless-sync yes, the default since 7.0). Meanwhile, new writes are kept in the replica's output buffer, and after the replica has loaded the snapshot, the buffered writes follow.

So the replica needs a full sync when it is new, when it was following a history the primary does not know, or when it has been away long enough that the bytes it missed have already been overwritten in the backlog. With the default 1 MB backlog and a primary writing 2 MB per second, that is any disconnection longer than half a second.

4Failovers and Restarts Keep Partial Sync Possible

When a replica is promoted, it starts a new replication ID, because from that moment its history may diverge from the old primary's. But it keeps the old ID as master_replid2, with the offset at which it switched. The other replicas, which were following the old primary with the old ID, can then PSYNC to the new primary and continue partially, as long as their offset is within the new primary's backlog. This is PSYNC version 2, introduced in Redis 4.0.

Since Redis 4.0, a node that is restarted can also resume partially: the replication ID and offset are stored in the RDB file, so after loading it the node knows which point in history it represents and can ask its primary for only the missing part.

5Replica Reads and Expiring Keys

Replicas are read-only by default (replica-read-only yes), which protects against applications writing to a copy that will be overwritten. They also do not expire keys on their own. Only the primary decides when a key has expired, and it sends an explicit DEL to the replicas. A replica that is asked for a key whose TTL has passed returns it as missing, even though the key is still in its memory until the DEL arrives. This keeps replicas consistent with the primary instead of each replica expiring keys on its own clock.

6Follow-up questions

Why does a too small backlog turn a short network blip into a full sync?

Because the backlog only keeps the last repl-backlog-size bytes of the write stream. If the replica was gone for longer than the backlog covers, the bytes it missed have been overwritten and the primary can no longer send just the difference. At 2 MB of writes per second, a 1 MB backlog covers half a second, so a 5-second blip forces a full snapshot of the entire dataset. Sizing the backlog to write rate times a realistic disconnection, say 60 seconds, avoids this.

Does WAIT make Redis replication synchronous?

Not fully. WAIT 1 100 blocks the client until at least one replica has acknowledged its writes or 100 ms have passed, which reduces the chance of losing them. But writes are still applied on the primary first, and a failover can still pick a replica that did not receive them, so it improves durability without giving strong consistency.

What does a replica do while it loads the RDB?

By default it loads the new snapshot and answers commands with a LOADING error until it is done. Newer versions can keep serving the old dataset during a diskless load, depending on repl-diskless-load, so check your configuration.

7Conclusion

In this answer, we saw that a primary streams writes to replicas asynchronously after replying to clients, and that replicas acknowledge their offset every second. The replication ID and offset name a point in the dataset's history, the backlog lets a reconnecting replica fetch only what it missed, and a full sync from an RDB snapshot is needed when the history is unknown or the gap is larger than the backlog. Promoted replicas keep the old ID as a secondary ID, restarted nodes resume from their RDB file, and replicas are read-only and leave expiry to the primary.

What to say in the interviewAbout 100 seconds aloud

Open with

Redis replication is asynchronous. The primary executes a write, replies to the client, and then streams the same command to every replica, and each replica reports its processed offset about once a second with REPLCONF ACK.

Then, if they want more

Each primary has a replication ID, which names one history of the dataset, and an offset, a byte counter in that history, so the pair identifies an exact point. When a replica connects it sends PSYNC with the ID and offset it last saw.

If the primary recognises that ID and the offset is still inside its replication backlog, a ring buffer of recent writes that is 1 megabyte by default, it sends only the missing bytes.

Otherwise it does a full sync: it forks to produce an RDB snapshot, writes it to disk or streams it diskless, keeps new writes in the replica's output buffer meanwhile, and sends them once the replica has loaded the snapshot.

A brand-new replica, an unknown ID, or a gap larger than the backlog all force a full sync, which is why I size the backlog for realistic disconnections.

After a failover the promoted replica keeps the old ID as a secondary one, so the other replicas can continue partially, and since Redis 4 a restarted node can resume from the ID and offset in its RDB.

Finally, replicas are read-only by default and do not expire keys themselves; they hide expired keys on reads and wait for the primary's DEL.

About this answer

Last updated
13 November 2026
Versions it names
Redis 4
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 "How does Redis replication work from the moment a replica connects, what are the...": https://scrivio-interview-library.netlify.app/databases/redis-scaling/3354181903/