Databases 10 min read

How Redis Sentinel Implements Automatic Failover

This article explains how Redis Sentinel provides automatic failover by combining multi‑replica deployment, health monitoring, leader election, and distributed consensus to detect master failures, select a new master, promote it, and notify clients, ensuring high availability for Redis databases.

Architect's Tech Stack
Architect's Tech Stack
Architect's Tech Stack
How Redis Sentinel Implements Automatic Failover

Deployment Modes

Redis can be deployed in several modes, each offering different availability levels: single-node, master‑slave, and master‑slave with Sentinel. Single‑node has no redundancy; master‑slave separates reads and writes; adding Sentinel provides automatic failover.

High‑Availability Approach

Redis uses native master‑slave replication to keep slaves synchronized with the master. When the master fails, a slave must be promoted. Manual promotion is slow, so Sentinel automates detection and promotion.

Sentinel Overview

Sentinel is a service that monitors Redis instances, sends notifications, and performs automatic failover. By configuring the master address, Sentinel discovers the full topology, monitors health, and coordinates recovery.

Working Principle

Sentinel’s workflow includes state awareness, heartbeat detection, leader election, selecting a new master, failover, and client notification.

State Awareness

Sentinel periodically sends the info command to each master to retrieve topology information, including slave addresses, and subscribes to pubsub channels to exchange status with other Sentinels.

Heartbeat Detection

Every second each Sentinel sends ping to masters, slaves, and other Sentinels. If a node does not respond within a configurable timeout it is marked as subjectively down; only after a majority of Sentinels agree is it considered objectively down.

Leader Election

Sentinels elect a leader using a consensus‑like process similar to Raft: each sets a random timeout, requests votes, and the first to obtain a majority becomes the leader that drives the failover.

Selecting a New Master

The leader chooses a slave based on slave‑priority, data completeness, and then the smallest runid. The chosen slave is promoted.

Promoting the New Master

The leader sends slaveofnoone to the selected slave, turning it into a master, then issues slaveof $newmaster to the remaining slaves so they replicate from the new master. Finally, the failed node is demoted to a slave.

Client Awareness

After failover, Sentinel publishes the new master address via pubsub. Clients can subscribe to this channel or query Sentinel directly to obtain the current master. Sentinel also supports hook scripts to notify applications.

Conclusion

Redis Sentinel combines multi‑replica deployment with automatic fault detection and recovery, employing distributed consensus to ensure accurate and fast failover, which is essential for high‑availability Redis deployments.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Distributed Systemshigh availabilityredissentinelDatabase Replicationautomatic failover
Architect's Tech Stack
Written by

Architect's Tech Stack

Java backend, microservices, distributed systems, containerized programming, and more.

0 followers
Reader feedback

How this landed with the community

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.