Understanding Redis Master‑Slave Replication: Full and Incremental Sync Explained
This article explains Redis master‑slave replication, covering the roles of master and replica, the full‑copy synchronization process, the incremental sync mechanism, and the step‑by‑step workflow illustrated with diagrams to help engineers implement reliable high‑availability data stores.
Redis Master‑Slave Replication Overview
Redis provides a master‑slave replication feature that enables read‑write separation and high availability. The master node handles all write operations and propagates data changes to one or more replica (slave) nodes, which primarily serve read requests.
Replication Mechanism
Replication consists of two phases: a full (initial) copy and an incremental (continuous) sync.
1. Full Synchronization
Trigger scenario: When a replica connects to the master for the first time.
Characteristics: All data is transferred, which can be time‑consuming and bandwidth‑intensive, but guarantees complete data consistency.
Process:
Replica sends PSYNC ? -1 request to the master.
Master runs BGSAVE to generate an RDB snapshot.
Master streams the RDB file to the replica.
Replica clears its old data and loads the received RDB.
Master sends any buffered write commands; replica executes them.
Full sync completes and replication switches to incremental mode.
2. Incremental Synchronization
Trigger scenario: After a brief disconnection, the replica reconnects to the master.
Characteristics: Only commands generated during the outage are transferred, resulting in fast, low‑overhead synchronization.
Process:
Replica sends PSYNC <runid> <offset> to the master.
Master checks its replication backlog for the requested offset.
If the offset exists, the master streams only the missing commands (incremental sync).
If the offset is missing, the master falls back to a full synchronization.
Replica applies the received command stream to catch up with the master.
These steps ensure that replicas stay up‑to‑date with minimal latency while providing a reliable fallback to full sync when necessary.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
