Databases 4 min read

How Redis Master‑Slave Replication Works: Full and Incremental Sync Explained

This article explains Redis master‑slave replication, detailing the full synchronization process that creates an RDB snapshot and streams buffered writes, as well as the incremental synchronization that resumes after a disconnection using PSYNC and the replication backlog.

Architect Chen
Architect Chen
Architect Chen
How Redis Master‑Slave Replication Works: Full and Incremental Sync Explained

Redis Master‑Slave Replication Overview

Redis replication provides high availability and read/write separation by allowing a master node to synchronize its data to one or more slave nodes in real time.

The master handles write operations, while slaves serve read requests; any change on the master is automatically propagated to the slaves.

Full Replication Process

Slave initiates synchronization by executing replicaof <master_ip> <master_port> and sending PSYNC ? -1 to request a full copy.

Master creates an RDB snapshot using BGSAVE, while buffering subsequent write commands.

Master transfers the generated RDB file to the slave. The slave receives the file, clears its old data, and loads the new snapshot.

After loading, the master sends the buffered write commands to the slave to reconcile any changes that occurred during snapshot creation.

Once the slave catches up, the master continuously streams new write commands, maintaining real‑time synchronization.

Incremental Replication Process

When a connection interruption occurs, the slave reconnects and sends PSYNC <runid> <offset>, where runid is the master’s unique identifier and offset is the last replicated position.

Master checks its replication backlog buffer. If the backlog still contains data after the given offset, it replies +CONTINUE; otherwise it replies +FULLRESYNC, triggering a full replication.

For a +CONTINUE response, the master streams the buffered commands starting from the offset to the slave, which executes them to catch up, after which normal real‑time sync resumes.

The incremental mechanism enables fast recovery after brief network outages without repeating the costly full snapshot transfer.

databaseRedismaster‑slavereplicationIncremental SyncFull Sync
Architect Chen
Written by

Architect Chen

Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.