Skip to content

Lesson 2 of 9 · 24m

Replication and Sentinel: Designing for the Node That Dies

Asynchronous replication, replication lag, failover quorum, split brain, and why a replica is not a backup.

Replication exists because one process on one machine will eventually fail. The uncomfortable part is that Redis replication is asynchronous by default: a successful write on the master may not have reached any replica yet. During failover, those writes vanish. Sentinel makes failover automatic, but it cannot change physics.

Replication is a stream of writes

A replica connects to a master and receives either a full synchronization or a partial continuation:

redis-cli -h replica.internal INFO replication

Important fields include:

role:slave
master_link_status:up
master_last_io_seconds_ago:1
master_repl_offset:918273645
slave_repl_offset:918273600

If master_link_status is down, the replica is drifting. If offsets are far apart, it may be connected but behind. A replica can serve stale reads while looking perfectly healthy to a load-balancer health check.

Full resynchronization is expensive

When a replica cannot continue from the replication backlog, the master forks and sends a snapshot. Large datasets mean minutes of disk, network, and copy-on-write pressure. Size the backlog for real restart windows:

repl-backlog-size 256mb
repl-backlog-ttl 3600

Sentinel is consensus plus choreography

Sentinel monitors masters, reaches quorum that a master is down, elects a leader sentinel, promotes a replica, and reconfigures the others. A minimal configuration looks like:

sentinel monitor cart-master 10.0.3.11 6379 2
sentinel down-after-milliseconds cart-master 5000
sentinel failover-timeout cart-master 60000
sentinel parallel-syncs cart-master 1

Quorum 2 means two sentinels must agree the master is objectively down. That is not the same as requiring two replicas or guaranteeing zero data loss.

Clients are part of failover

Applications must discover the new master through Sentinel-aware clients or an equivalent control plane. Hard-coding the old master IP means your automatic failover succeeds and the application still writes nowhere. Promotions also create a write gap. Some clients retry cleanly; others surface errors. Test the behavior — a failover drill that you only observe in logs is not a drill.

Split brain is the dangerous success case

If a network partition isolates the old master but clients can still reach it, both sides may accept writes. When the partition heals, one side's writes are discarded by design. min-replicas-to-write can reduce this:

min-replicas-to-write 1
min-replicas-max-lag 10

This is a safety brake, not absolute consistency.

Field notes

  • A replica copies corruption and deletion too; FLUSHALL replicates quickly and faithfully. Replicas are availability, not backups.
  • Read scaling through replicas accepts stale reads. Put that in the product requirements before enabling it.
  • Three Sentinels on separate failure domains is the floor; one Sentinel is monitoring, not consensus.
  • Watch sentinel logs during maintenance. Most accidental failovers are caused by operators freezing or stressing a master just long enough to look dead.

Was this lesson helpful?

Sign in to rate