Skip to content

Redis Sentinel deep dive — automatic failover end to end

How Sentinel detects master failure, runs leader election, promotes a replica, reconfigures the topology, and notifies clients — with the timing knobs that actually matter.

Redis Sentinel is the original Redis HA approach — a set of sentinel daemons that monitor master and replica Redis instances, agree when a master is down, elect a sentinel to run the failover, promote a replica, and reconfigure the rest of the topology. It is not magic, and the timing knobs interact in non-obvious ways. This article walks through a full failover end to end, names every state the sentinel cluster moves through, and points out the configuration values that drive the difference between a 5-second recovery and a 60-second outage.

How to verify

# Sentinel cluster state
redis-cli -p 26379 INFO sentinel
redis-cli -p 26379 SENTINEL masters
redis-cli -p 26379 SENTINEL replicas mymaster
redis-cli -p 26379 SENTINEL sentinels mymaster

# Current master from any sentinel
redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster

# Failover history
sudo journalctl -u redis-sentinel --since "1 hour ago" | grep -E '+sdown|+odown|+vote-for-leader|+failover|+switch-master'

What’s happening

A Sentinel deployment is at minimum three sentinel daemons (so a majority vote is possible), running alongside the Redis instances they monitor. Each sentinel pings every monitored Redis with PING every sentinel down-after-milliseconds. When pings start failing, the sentinel marks the master +sdown (subjectively down). That alone does nothing. The sentinel asks other sentinels whether they also see the master as down; once a quorum agrees, the master moves to +odown (objectively down) and failover begins.

Failover proceeds through these states:

  1. Leader election. Sentinels run a Raft-like election to pick the one sentinel that will execute the failover. The winner is the sentinel that gets votes from a majority of sentinels.
  2. Replica selection. The leader picks the best replica to promote, ordering by: configured replica-priority, replication offset (most up-to-date), runid (tiebreaker).
  3. Promotion. The leader sends REPLICAOF NO ONE to the chosen replica, watches for it to confirm, and then sends REPLICAOF <new-master> to the remaining replicas.
  4. Topology rewrite. Each sentinel persists the new topology to disk and rewrites its own configuration. The new master is now authoritative.
  5. Notification. Sentinels publish on +switch-master Pub/Sub channel; subscribed clients receive the new master address.

The total failover time is approximately down-after-milliseconds + election-time + promotion-confirmation. With the default down-after-milliseconds = 30000 and failover-timeout = 180000, the floor is 30 seconds. Tuning those down to 5000 and 30000 gets sub-10-second failover on a healthy network — but lower values increase false positives.

The procedure (failover walkthrough)

  1. Provision three sentinels on three different hosts. Each /etc/redis/sentinel.conf:

    port 26379
    daemonize no
    pidfile /var/run/redis-sentinel.pid
    logfile /var/log/redis/sentinel.log
    dir /var/lib/redis
    
    sentinel monitor mymaster 10.0.0.11 6379 2
    sentinel down-after-milliseconds mymaster 5000
    sentinel failover-timeout mymaster 30000
    sentinel parallel-syncs mymaster 1
    sentinel auth-pass mymaster strong-password

    The 2 is the quorum — minimum sentinels that must agree the master is down.

  2. Start each sentinel under systemd:

    sudo systemctl enable --now redis-sentinel
    sudo systemctl status redis-sentinel --no-pager
  3. Watch sentinel converge. All three should know about each other and report two replicas:

    redis-cli -p 26379 SENTINEL sentinels mymaster | grep name
    redis-cli -p 26379 SENTINEL replicas mymaster | grep name
  4. Trigger a failover. Either kill the master process or SHUTDOWN NOSAVE from inside it. Watch the log of one sentinel:

    sudo journalctl -u redis-sentinel -f
    # +sdown master mymaster 10.0.0.11 6379
    # +odown master mymaster 10.0.0.11 6379 #quorum 2/2
    # +vote-for-leader <runid> 1
    # +elected-leader master mymaster 10.0.0.11 6379
    # +failover-state-select-slave master mymaster
    # +selected-slave slave 10.0.0.12:6379
    # +failover-state-send-slaveof-noone slave 10.0.0.12:6379
    # +promoted-slave slave 10.0.0.12:6379
    # +switch-master mymaster 10.0.0.11 6379 10.0.0.12 6379
  5. Verify the client receives the new master. A Sentinel-aware client subscribes to +switch-master and refreshes its connection.

    redis-cli -p 26379 SUBSCRIBE +switch-master
  6. Recover the old master. When you restart it, it discovers (via sentinel-published config) that it should be a replica of the new master and syncs accordingly.

  7. Run a planned failover the same way — SENTINEL failover mymaster triggers an orderly switch with the old master gracefully demoted instead of killed.

Common pitfalls

  • An even number of sentinels (2, 4) cannot elect a leader during a split-brain scenario because no majority is reachable. Always run an odd number — three minimum.
  • Co-locating a sentinel on the same host as the master means a single host failure takes out one Redis and one sentinel. Sentinels should live on application hosts or on separate observer hosts.
  • down-after-milliseconds set too low (e.g. 1000) plus a brief network glitch produces a spurious failover. We use 5000 ms as a baseline; below that, you need a very stable network.
  • A sentinel that cannot reach the replica’s host (firewall blocks the replica’s IP) will not see the replica come up after promotion and will repeatedly trigger failover attempts. Verify sentinel-to-replica reachability, not just sentinel-to-master.
  • A client that connects directly to a master IP (not via sentinel) does not know failover happened — connections silently break. All clients must use a Sentinel-aware library or sit behind a TCP proxy that reads +switch-master.

In the engagements we run, every Sentinel-managed Redis comes with a smoke test that triggers SENTINEL failover once a month and times the recovery — anything over 10 seconds is an alert. We operate Sentinel-based HA under Managed Operations, and for the testing playbook see Sentinel failover testing.