Redis replication

  • Compare partial resynchronization with snapshot transfer after a replica disconnects.
100%
Primary serverReplica serverOne dataset history, two synchronization pathsDiscovery / coordinationStored dataReplicationwritesretain bytesfull synclive streamapplyrequest next offsetretained suffixsnapshot + catch-upThe primary executes the write and produces a stream describing changes. Replication offsets count stream bytes.WritablekeyspaceThe primary identifies its dataset history and advances a byte offset as it generates the stream. An offset identifies progress only within a compatible history.Replication IDand byte offsetFull synchronization creates and transfers a snapshot; diskless mode can stream it from a child. Updates arriving after the snapshot point must also reach the replica.RDB snapshotat sync pointThe bounded in-memory history supports partial synchronization while a reconnecting replica’s next required byte is still retained.Backlog ofrecent bytesOn reconnect the replica requests synchronization using the known history and offset. A compatible secondary ID may also be accepted within its retained offset boundary after promotion.Applied historyID and offsetSteady replication applies streamed changes. A full resync replaces the dataset and catches up with changes received since the snapshot.Replicakeyspacewritesretain bytesfull synclive streamapplyrequest next offsetretained suffixsnapshot + catch-up

Select a component to trace its direct connections. Drag to pan · Ctrl + wheel or pinch to zoom.

  • A replica remembers which stream it followed and how many bytes it applied. The primary’s backlog holds a rolling window of that stream.
  • At 4 MiB/s, a filled 64 MiB backlog covers about 16 seconds. A replica on the same history can recover a 10-second gap by requesting the missing bytes.
  • After a 20-second gap at that rate, the oldest missing bytes are gone. Redis transfers a dataset snapshot and the writes made since that snapshot.
  • A compatible replication ID and a retained offset allow a replica to receive just the missing suffix. A new replica or a missing history range needs full synchronization.
  • A full sync transfers the dataset and catches up subsequent writes. High write rates shorten the backlog window and increase catch-up demand.
Redis replication

Redis replication

Redis Open Source 7.2 architecture

Size the reconnect window

  • A filled 64 MiB backlog and a steady 4 MiB/s replication stream hold roughly 16 seconds of history. Use measured replication-offset growth, including bursts, when sizing the backlog.
  • A 10 s interruption misses about 40 MiB. An eligible replica on the same history can resume from its next offset if the suffix is retained.
  • A 20 s interruption misses about 80 MiB. Here the head of the missing range has been overwritten. The replica needs a full sync even when both servers have otherwise healthy storage.
  • A short gap can also need full sync when the requested history is unknown. A promoted primary can recognize its predecessor’s ID up to a recorded offset.
Which reconnects fit the backlog?json
{
  "kind": "illustrative PSYNC reconnect cases",
  "replicationId": "H1 (symbolic)",
  "backlogBytes": 67108864,
  "steadyStreamBytesPerSecond": 4194304,
  "nominalHistorySeconds": 16,
  "assumptions": "Backlog is active, filled and retained. Rate is constant and includes all replication-stream bytes.",
  "cases": [
    {"history": "H1", "disconnectedSeconds": 10, "missingBytes": 41943040, "expected": "partial if requested offset retained"},
    {"history": "H1", "disconnectedSeconds": 20, "missingBytes": 83886080, "expected": "full because required bytes have rolled out"},
    {"history": "unknown", "disconnectedSeconds": 1, "missingBytes": 4194304, "expected": "full because history is incompatible"}
  ]
}

Account for the full-copy cost

  • The primary supplies an RDB snapshot, potentially through diskless transfer, and buffers/streams subsequent changes. The replica loads the image and applies the catch-up stream.
  • Size bandwidth, memory and disk headroom for resync during normal write traffic. Several disconnected replicas can compete with client traffic when they return.
  • A read served from a replica can trail a committed primary write. For a read with a freshness requirement, route or validate it against the application’s consistency contract.
  • Observe primary and replica offsets, link state and full/partial synchronization counters. Separate slow application reads from lag in the replication link.