Databases 4 min read

How Redis Master‑Slave Replication Enables Real‑Time Sync, Read/Write Separation, and Failover

This article explains Redis master‑slave replication, covering its purpose for data redundancy, read/write separation, and high availability, and details the full‑synchronization and incremental‑synchronization processes with step‑by‑step diagrams.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
How Redis Master‑Slave Replication Enables Real‑Time Sync, Read/Write Separation, and Failover

Redis Master‑Slave Replication Overview

Redis replication provides high availability and read/write separation by continuously copying data from a master node to one or more slave nodes. The slave holds an exact copy of the master’s dataset, enabling read‑only traffic to be offloaded and allowing a slave to be promoted when the master fails.

Full‑Synchronization Process

Triggered when a slave connects for the first time or after a prolonged disconnection.

Handshake & Authentication – The slave sends a replication request ( PSYNC or the legacy SYNC) that includes its last known replication offset, or an empty offset for a fresh connection.

Master Generates RDB Snapshot – The master forks a child process that dumps the current database into an RDB file while still accepting write commands.

Transfer & Load – The master streams the RDB file to the slave. The slave writes the snapshot to local storage, loads it into memory, and establishes a consistent baseline.

Diagram of Redis full‑synchronization process
Diagram of Redis full‑synchronization process

Incremental (Partial) Synchronization Process

Used when the master‑slave link remains alive or is briefly interrupted, allowing the slave to catch up without a full RDB dump.

Ring Buffer Maintenance – The master keeps a fixed‑size circular buffer that records recent write commands together with their global replication offsets.

Offset Comparison – Upon reconnection, the slave reports the last offset it processed.

Partial Resynchronization (PSYNC) – If the master still retains the requested offset in its buffer, it streams only the missing commands.

Command Application – The slave applies the received commands directly, avoiding another RDB dump and reducing latency and resource consumption.

Diagram of Redis incremental synchronization process
Diagram of Redis incremental synchronization process

Key Characteristics

Data Redundancy – Slaves store exact copies of the master’s data.

Read/Write Separation – Writes are handled by the master; reads can be served by slaves, reducing load on the primary.

High Availability – In case of master failure, a slave can be promoted to master, ensuring continuity.

backenddatabasehigh availabilityRedismaster‑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.