Lesson 7 of 9 · 27m
Replication and Failover Without Fairy Tales
Understand asynchronous replication, replica lag, promoted-write loss, Sentinel behavior, client failover, and safe operational checks.
Redis replication is simple to configure and easy to misunderstand. A replica is not a synchronous safety copy. It is a follower that applies a replication stream asynchronously. During normal operation the lag may be milliseconds. During failure, deploy, network partition, or overload, that gap becomes the exact amount of write loss you may accept.
Build the topology deliberately
# on the replica
replicaof 10.20.30.10 6379
replica-read-only yes
repl-diskless-sync yesInspect both sides:
redis-cli info replicationOn the primary, look for connected replicas, replication backlog, and offsets. On the replica, compare master_repl_offset with the replica's slave_repl_offset and inspect master_link_status. "Connected" does not mean caught up forever; it means the link exists at that moment.
The replication backlog is your safety margin
When a replica disconnects briefly, Redis can perform a partial resynchronization if the needed writes are still in the primary's backlog:
repl-backlog-size 64mb
repl-backlog-ttl 3600If the replica is away too long or the write volume overruns the backlog, it needs a full synchronization. Full sync means fork, transfer, load, and memory pressure. During incidents, teams often create the very load spike that makes failover worse by reconnecting several stale replicas simultaneously.
Failover can lose acknowledged writes
Because replication is asynchronous, a primary can acknowledge a write and fail before the replica receives it. If that replica is promoted, the write disappears. This is not a bug or a configuration mistake; it is the replication model. Applications needing stronger guarantees must use synchronous systems, external logs, compensating workflows, or accept bounded loss.
Sentinel coordinates, it does not perform magic
Redis Sentinel monitors primaries, reaches quorum, and promotes replicas. A minimal deployment uses multiple sentinels on separate failure domains:
sentinel monitor app-redis 10.20.30.10 6379 2
sentinel down-after-milliseconds app-redis 5000
sentinel failover-timeout app-redis 30000
sentinel parallel-syncs app-redis 1Clients must discover the new primary through Sentinel-aware drivers. Hard-coded IPs plus failover equals a write split. During partition scenarios, old-primary clients can continue writing unless min-replica and client behavior constrain them.
Practice the boring failure cases
Do not wait for a primary failure to learn client behavior. In a lab or staging environment test:
primary process kill
network partition
replica promotion
old primary rejoining
Sentinel quorum loss
client DNS/cache behaviorMeasure time to detection, time to promotion, write errors, stale reads, and duplicated side effects. Redis failover is a distributed-systems event, not a health-check checkbox.
Field notes
- Replicas are excellent for read scaling only if the application accepts replication lag.
WAITcan block until replicas acknowledge, but it is not a general synchronous-replication guarantee and affects latency.- Never point every read at replicas without monitoring lag; stale session and entitlement reads create bizarre application bugs.
- Old primaries rejoining after failover can hold stale writes. Understand how they reconcile before celebrating recovery.
Was this lesson helpful?