Redis replication is asynchronous, append-only, and ships every write from the master to each replica through an in-memory backlog and a per-replica output buffer. When it works it is invisible; when it breaks, you get cascading full resyncs that pin disk I/O, balloon memory, and produce thundering-herd patterns when replicas reconnect. This article covers the buffers and timing values that govern partial-sync (PSYNC) vs full-sync behavior, the sizing math, and the verifications that prove a replication topology is healthy.
How to verify
# Replica side
redis-cli -h replica -a "$PASS" INFO replication
# Look for: role:slave, master_link_status:up, master_sync_in_progress:0,
# master_last_io_seconds_ago, master_link_down_since_seconds
# Master side — replication backlog and per-replica lag
redis-cli -h master -a "$PASS" INFO replication
# Look for: connected_slaves, repl_backlog_active, repl_backlog_size,
# lag (per replica)
# Verify the master is not buffering toward the replica's limit
redis-cli -h master -a "$PASS" CLIENT LIST TYPE replica
What’s happening
When a replica connects, it tries PSYNC <runid> <offset> — “give me everything since this offset”. The master checks two things: does its runid match (i.e., has it not restarted), and is the offset still inside the in-memory replication backlog ring buffer? If both yes, the master replays the missing writes — partial sync. If either no, the master triggers BGSAVE to disk, ships the RDB to the replica, then resumes the live stream — full sync.
Full sync is expensive: fork-induced memory copy on the master, network bandwidth for the full dataset, disk I/O on the replica to load, and a window where the replica is fully busy. On a 30 GB dataset with a 1 Gbps link, the full sync alone is several minutes and the master forks COW pages for the duration.
The replication backlog is sized by repl-backlog-size (default 1 MB, which is laughably small for any non-trivial deployment). It is a ring buffer of the most recent N bytes of the replication stream. If a replica is disconnected longer than it takes to write N bytes on the master, the offset falls outside the backlog and the next PSYNC becomes a FULLSYNC.
The per-replica output buffer is sized by client-output-buffer-limit replica. If a replica is slower than the master’s write rate plus its own apply rate, it lags; once the lag exceeds the limit, the master disconnects the replica, which then reconnects and triggers a full sync.
The procedure
-
Size the replication backlog to cover the longest expected disconnect. Rule of thumb:
repl-backlog-size = peak-write-rate-bytes-per-second * worst-acceptable-disconnect-seconds. For 10 MB/s writes and a 5-minute acceptable disconnect, you want 3 GB.# /etc/redis/redis.conf on the master repl-backlog-size 512mb repl-backlog-ttl 3600 -
Size
client-output-buffer-limit replicagenerously — the default 256 MB hard limit can disconnect during a burst. We baseline 1 GB hard, 256 MB soft, 60 second window:client-output-buffer-limit replica 1gb 256mb 60Format is
<class> <hard-limit> <soft-limit> <soft-seconds>. -
Tune timeouts so that a brief network glitch does not declare the link dead:
repl-ping-replica-period 5 repl-timeout 30 -
Set
min-replicas-to-writeif you want to refuse writes when replicas fall behind — protects against partial-data scenarios at the cost of availability:min-replicas-to-write 1 min-replicas-max-lag 10 -
Watch replication health with INFO and alert on the right signals:
master_link_status:downon a replica.master_last_io_seconds_ago> 5 seconds.lag> 5 seconds.repl_backlog_active:0on the master (backlog evaporated, every reconnect is FULLSYNC).
-
Trigger a planned full sync to validate the timing — useful before peak season:
redis-cli -h replica REPLICAOF NO ONE sleep 5 redis-cli -h replica REPLICAOF master-host 6379 redis-cli -h replica INFO replication | grep sync_in_progress -
For Redis Cluster, all of the above applies to each shard’s master-replica pair independently. The cluster bus does not carry replication data; it only carries gossip.
Common pitfalls
- The default
repl-backlog-size 1mbcauses a FULLSYNC on every disconnect longer than a second of high-write traffic. Bump it. - A FULLSYNC during peak load can produce a thundering herd: the BGSAVE forks COW pages, the replica reload pegs disk, and other replicas time out and reconnect, triggering more FULLSYNCs. Stagger replica restarts.
client-output-buffer-limit replica 0 0 0(no limit) sounds safer but lets a hung replica buffer until the master runs out of memory. Set sane limits.- Replication runs in a single thread on the master in older versions; in Redis 6+, IO threads help, but the writer still serializes. CPU-bound masters on small instances simply cannot keep three replicas in sync.
- TLS on replication (
tls-replication yes) adds CPU cost — measure it before assuming a previously working setup remains fine after the security flip.
In the engagements we run, every Redis master comes up with a backlog sized to peak-write-rate times five minutes, min-replicas-to-write 1 for primaries, and Prometheus alerts on connected_slaves, master_last_io_seconds_ago, and repl_backlog_active. We operate that under Managed Operations — and for Sentinel-driven topologies the Sentinel deep dive explains the failover layer that sits on top of replication.