Understanding Redis Replication: Sync, Command Propagation, and PSYNC Explained
This article explains Redis replication's two core mechanisms—synchronization and command propagation—detailing the SYNC workflow, how masters propagate writes to slaves, and how the PSYNC command enables efficient partial resynchronization after disconnections.
Redis replication consists of two operations: synchronization (sync) and command propagation.
Synchronization
The slave synchronizes with the master by sending the SYNC command. The process is:
Slave sends SYNC to master.
Master runs BGSAVE, creates an RDB file, and starts buffering all subsequent write commands.
Master sends the RDB file to the slave; the slave loads it, updating its state to the point of BGSAVE.
Master sends the buffered write commands to the slave; the slave executes them, bringing its state up to the master’s current state.
Command propagation
After synchronization, the master and slave are consistent, but any new write command on the master can break this consistency. To restore it, the master forwards the offending write command to the slave, which executes it, re‑establishing consistency.
Handling disconnection
Before Redis 2.8, a reconnection triggered a full resynchronization: the master rewrote its database to a file and sent it to the slave, which was resource‑intensive.
Since Redis 2.8, the PSYNC command enables partial resynchronization. The master records write operations that occurred during the disconnection; when the slave reconnects, it receives only those recorded writes and applies them, updating its state to the master’s current state.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
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.
