Redis replication: primary-replica setup and how replication works
primary-replica architecture, REPLICAOF command, full resync, partial resync, replication offset, read scaling with replicas, replication lag, async replication caveat
Primary-replica replication
Redis replication is asynchronous. One primary accepts writes. One or more replicas receive a copy of every write and serve read traffic.
Setting up a replica
# On the replica server (redis.conf or runtime)
REPLICAOF 192.168.1.10 6379
# Verify replication status
redis-cli INFO replication
# role:slave
# master_host:192.168.1.10
# master_link_status:up
# master_repl_offset:12345How replication works
On first connect, the replica triggers a full resync: the primary creates an RDB snapshot and streams it to the replica, then sends buffered writes. After sync, every write to the primary is forwarded to replicas. Partial resync reconnects a temporarily disconnected replica using the replication offset — no full snapshot needed if the backlog covers the gap.
Limitations
Replication is asynchronous. A primary can acknowledge a write to the client before it reaches replicas. If the primary crashes at that instant, the write is lost. For stronger guarantees, use WAIT N TIMEOUT to block until N replicas confirm the write. Replicas are read-only by default — writes to a replica are rejected.
