Sentinel and Failover

You’ve secured your data with RDB and AOF. But what if the server itself dies? Your application will still experience downtime. To prevent this, we use Redis Sentinel.

1. What is Sentinel?

Redis Sentinel is a distributed system that monitors your Redis instances and performs the following tasks:

  • Monitoring: Periodically checks if your Master and Replica instances are working as expected.
  • Notification: Alerts your application or system administrator when something goes wrong.
  • Automatic Failover: If the Master dies, Sentinel promotes a Replica to be the new Master.
  • Configuration Provider: Acts as a source of truth for clients to find the current Master’s IP address.

2. The Quorum

Sentinel is a distributed system itself. To avoid “Split Brain” scenarios (where two nodes think they are the Master), Sentinels use a Quorum.

  • If you have 3 Sentinels and a Quorum of 2, at least 2 Sentinels must agree that the Master is down before a failover is triggered.
  • Once agreed, the Sentinels elect a Leader among themselves to carry out the failover.

3. The Failover Process

  1. Detection: Master stops responding to PINGs.
  2. S_DOWN: A single Sentinel marks the master as Subjectively Down.
  3. O_DOWN: Quorum is reached; the master is Objectively Down.
  4. Election: Sentinels pick the best Replica (based on priority and replication offset).
  5. Promotion: The picked Replica is promoted to Master. All other Replicas are told to follow the new Master.

4. Interactive: Sentinel Failover

Kill the Master and watch Sentinel promote a Replica.

MASTER
⬅️
👁️
Sentinel
➡️
REPLICA
Ready
Status: Healthy

5. Summary

Sentinel is a key part of the Redis ecosystem for applications that cannot afford any downtime. It provides the automation needed to turn a manually managed database into a self-healing, high-availability system.