Databases 5 min read

Master‑Slave Replication in Redis: Full and Incremental Sync Explained

This article explains Redis master‑slave replication, covering its purpose for backup, read/write separation, and high availability, and details the seven‑step full‑copy process and the six‑step incremental sync process with illustrative diagrams.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Master‑Slave Replication in Redis: Full and Incremental Sync Explained

Redis Master‑Slave Replication Overview

Redis is a critical middleware in large‑scale architectures. Master‑slave replication copies data from a master node to one or more slave nodes, similar to MySQL replication, and consists of full‑copy and incremental‑copy phases.

By default each Redis instance acts as a master; a master may have multiple slaves, while a slave is linked to a single master.

Key Benefits

Data backup – slaves can take over when the master fails, enabling rapid failover.

Read/write separation – the master handles writes, slaves serve reads, improving load capacity.

High availability – master‑slave replication is the foundation for Redis Sentinel and cluster solutions.

Full‑Copy Replication Process

The initial synchronization follows seven steps:

Slave sends PSYNC to the master and establishes a long‑lived socket connection.

Master receives the command and executes BGSAVE to generate an RDB snapshot.

Master transmits the RDB file to the slave.

Slave clears its data and loads the received RDB.

Master streams any write commands that occurred during snapshot creation from its replication buffer to the slave.

Slave executes the received write commands.

Master continuously pushes subsequent write commands over the socket to keep master and slave consistent.

Full replication diagram
Full replication diagram

Incremental Replication Process

If the connection is lost and the master continues to receive writes, reconnection triggers incremental sync, which follows six steps:

Slave detects the broken connection.

Master retains recent write commands in its replication buffer.

Slave re‑establishes a socket connection to the master.

Slave issues PSYNC with an offset to indicate the last processed command.

Master checks whether the slave’s offset lies within the buffer; if so, it streams the missing commands, otherwise it falls back to a full copy.

Master continues to push new write commands over the socket to maintain consistency.

Incremental replication diagram
Incremental replication diagram
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

databaseMaster‑SlaveReplication
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

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.