The reason teams hit a real Sentinel failover and watch the recovery take three minutes instead of ten seconds is that nobody had tested it since deployment. Failover testing is a runbook with a fixed cadence — a planned SENTINEL failover, a kill-the-process test, and a network-partition simulation. This article is the playbook we use to prove Sentinel-managed Redis topologies are still failing over the way they should.
How to verify
# Baseline: what should happen?
redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster
redis-cli -p 26379 SENTINEL replicas mymaster | grep -E 'name|ip|port'
redis-cli -p 26379 SENTINEL ckquorum mymaster
# Expected: "OK 3 usable Sentinels. Quorum and failover authorization can be reached"
# Timing baseline — set this as the SLO
redis-cli -h current-master -a "$PASS" --latency-history -i 1 &
LATPID=$!
date +%s
# ... trigger failover ...
date +%s
kill $LATPID
What’s happening
A failover test has three goals:
- Confirm Sentinel still elects a new master. Quorum unchanged, replicas reachable, no network drift since the last test.
- Measure failover time. From the moment the master goes away to the moment clients write again. The SLO is typically 5-15 seconds depending on
down-after-milliseconds. - Verify client behavior. A Sentinel-aware client should drop connections to the old master, learn the new one via subscription to
+switch-master, and resume traffic without code-level errors. A misconfigured client gets stuck.
There are three test modes, ordered from gentle to invasive:
- Planned failover.
SENTINEL failover mymastertriggers an orderly switch with the old master gracefully demoted. Zero data loss, validates the election and replica selection. - Kill-the-process.
kill -9 <redis-pid>on the master. Triggers the natural detection cycle (subjective down → quorum → election → promotion). Validates the timeout settings and full path under crash. - Network partition. Drop traffic to the master with
iptables -A INPUT -p tcp --dport 6379 -j DROPor by isolating the host’s network interface. Validates Sentinel’s ability to detect a master that is “alive” but unreachable.
The right cadence in production: planned failover once a month, kill-the-process once a quarter on a staging clone, network partition once a quarter where infrastructure allows it.
The procedure
-
Pre-flight checks. Quorum reachable, replication healthy, backups recent:
redis-cli -p 26379 SENTINEL ckquorum mymaster redis-cli -h current-master -a "$PASS" INFO replication | grep -E 'role|connected_slaves|repl_backlog_active' redis-cli -h current-master -a "$PASS" LASTSAVEIf any of these fails, abort the test — fix the underlying issue first.
-
Start a latency probe from the application network:
redis-cli -h sentinel-aware-vip -a "$PASS" --latency-history -i 1 > /tmp/latency.log & -
Mark the test in monitoring. Add an annotation in Grafana / pagerduty so spikes are not misread as a real incident.
-
Trigger a planned failover. From any sentinel:
redis-cli -p 26379 SENTINEL failover mymaster # Returns: OKWatch the sentinel log:
sudo journalctl -u redis-sentinel -f | grep -E '\+switch-master|\+slave-reconf-done' -
Measure recovery time. From the
SENTINEL failovertimestamp to the+switch-masterevent should be under 10 seconds on a healthy topology. The latency probe should show a few seconds ofCould not connect to Redisthen resume. -
Validate client behavior. Watch your application’s metrics — error rate during the failover window. A well-behaved client shows a small spike of failed requests and then normal traffic. A misconfigured client shows persistent errors and needs manual intervention.
-
Run the kill-test on staging. SSH to the master, find the PID, kill it ungracefully:
PID=$(pgrep -f "redis-server.*6379") sudo kill -9 "$PID" date +%sRecovery time is
down-after-milliseconds+ election + promotion — should match within 1-2 seconds of the planned-failover test. -
Recover the killed master. It comes up, discovers via Sentinel that it should be a replica, and resyncs. Verify:
redis-cli -h previous-master -a "$PASS" INFO replication # role:slave # master_link_status:up -
Document the timings in a runbook entry. Outcome, recovery time, anything that changed since the last drill. Drift between drills is the warning.
Common pitfalls
- A drill that succeeds but takes 3x longer than the previous one means something has degraded — network, Sentinel reachability, replica health. Investigate before declaring success.
- A planned failover during peak load is risky for the wrong reason: not because the failover is unsafe, but because the latency hit during the gap is more visible. Schedule for off-peak.
- The latency probe must come from the application network, not from the Redis host. Probing from the same host masks the failover-window outage.
- A test on staging that does not mirror production’s
down-after-millisecondsandfailover-timeouttells you nothing about production timing. - After a kill-test, the old master may need its
replicaofline cleared fromredis.confifslaveofwas written explicitly — Sentinel handles this automatically via the runtime config, but a manualredis.confclears the line and the post-test recovery loops.
In the engagements we run, every Sentinel-managed Redis has a calendar entry for a monthly planned failover, a quarterly kill-test in staging, and a Prometheus alert if +switch-master events have not been seen in 35 days (drill drift). We operate that under Managed Operations — and the underlying mechanism is detailed in Sentinel deep dive.