Understanding Redis Partial Resynchronization: Offsets, Backlog Buffer, and Run ID
Redis partial resynchronization relies on three components—the master‑slave replication offset, the master’s replication backlog buffer, and the server run ID—to determine whether a slave can receive only missing data after a disconnection or requires a full sync.
Components of Partial Resynchronization
Partial resynchronization in Redis consists of three parts:
Master and slave replication offsets
Master's replication backlog buffer
Server run ID (run ID)
Replication Offset
Both master and slave maintain a replication offset. Each time the master sends N bytes to the slave, it increments its offset by N; the slave does the same upon receiving N bytes. For example, if both offsets are 10000 and the master sends 99 bytes, both offsets become 10099.
Scenario Example
Consider a master with three slaves A, B, and C, all at offset 10010. The master sends 33 bytes; B and C receive them, updating their offsets to 10043, while A disconnects and remains at 10010, causing data inconsistency. When A reconnects, it issues a PSYNC command with its offset (10010). The master must decide whether to perform a full or partial resynchronization.
Replication Backlog Buffer
The backlog buffer is a fixed‑length queue maintained by the master (default size 1 MB). Every write command sent to slaves is also enqueued in this buffer, preserving recent commands together with their offsets. When a slave reconnects and sends its offset via PSYNC, the master checks whether the data starting at offset+1 still resides in the backlog. If it does, the master sends only those missing commands (partial resync); otherwise, it performs a full resynchronization.
Applying the Scenario
In the example, slave A reports offset 10010. The master finds that the data after 10010 is still present in the backlog and sends all commands from that point onward, allowing A to catch up without a full sync.
Server Run ID
Each Redis server generates a unique run ID at startup, consisting of 40 random hexadecimal characters. During initial replication, the master transmits its run ID to the slave, which stores it. If a slave disconnects and later reconnects to a master, it sends the saved run ID. If the run ID matches, the slave is reconnecting to the same master and partial resynchronization may be attempted; if it differs, the master must perform a full resynchronization.
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.
