Databases 16 min read

How Redis Sentinel Ensures Automatic Failover and High Availability

Redis Sentinel provides a robust high‑availability solution by monitoring master‑slave clusters, automatically detecting failures, electing leaders, and performing failover, while using quorum voting, Pub/Sub communication, and configuration provisioning to ensure seamless master promotion and client redirection without manual intervention.

Sanyou's Java Diary
Sanyou's Java Diary
Sanyou's Java Diary
How Redis Sentinel Ensures Automatic Failover and High Availability

What is Redis Sentinel?

Redis Sentinel is a high‑availability mode that monitors master‑slave replication, detects failures, and automatically promotes a slave to master.

Diagram of Sentinel cluster
Diagram of Sentinel cluster

In a typical deployment three Sentinel instances monitor a master and two slaves.

Sentinels communicate with each other to form a cluster and elect a leader for failover.

Master and slaves form the replication topology.

Sentinels monitor the topology, provide notifications, perform automatic failover, and act as configuration providers.

Sentinel Tasks

Sentinel performs four main duties:

Monitoring : Periodically sends PING , INFO , and PUBLISH/SUBSCRIBE commands to check the health of masters and slaves.

Automatic Failover : When a master is deemed down, a leader sentinel promotes a suitable slave to master.

Notification : Informs clients and slaves of the new master using the REPLICAOF command.

Configuration Provider : Clients query any sentinel to obtain the current master address.

Monitoring Details

Sentinel marks a node as subjectively down (SDOWN) after missing down-after-milliseconds heartbeats. When a quorum of sentinels agree, the node becomes objectively down (ODOWN) and failover starts.

Valid PING replies are +PONG , -LOADING , or -MASTERDOWN . Any other reply or timeout is considered invalid.

Failover Process

Sentinels select a slave based on priority, replication offset, and run‑ID. The chosen slave receives the SLAVEOF NO ONE command to become master, after which other slaves are reconfigured to replicate from the new master.

Leader Election

When a master is subjectively down, each sentinel sends SENTINEL is-master-down-by-addr <master-ip> <master-port> <sentinel.current_epoch> to gather votes. The sentinel that obtains a majority (≥ quorum) becomes the leader and executes the failover.

Sentinel Cluster Implementation

Multiple sentinels avoid a single point of failure. They discover each other via Redis Pub/Sub on the sentinel:hello channel and exchange slave information through the master’s INFO command.

Sentinel discovery via Pub/Sub
Sentinel discovery via Pub/Sub

Failover voting follows a Raft‑like protocol; a quorum of at least three sentinels is recommended to ensure availability.

Pub/Sub Channels

Sentinel publishes events such as +sdown , -sdown , +odown , -odown , and +switch-master for masters, and +slave-reconf-sent , +slave-reconf-inprog , +slave-reconf-done for slaves.

Databasehigh availabilityredisSentinelFailover
Sanyou's Java Diary
Written by

Sanyou's Java Diary

Passionate about technology, though not great at solving problems; eager to share, never tire of learning!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.