Databases 7 min read

Mastering Redis Sentinel: Build a Cost‑Effective High‑Availability Solution

This article explains how Redis Sentinel provides automatic failover, monitoring, and client notification, outlines its configuration, compares three methods for receiving failover messages, and recommends a service‑level indirect reception design for scalable, low‑cost high availability.

ITFLY8 Architecture Home
ITFLY8 Architecture Home
ITFLY8 Architecture Home
Mastering Redis Sentinel: Build a Cost‑Effective High‑Availability Solution

Redis Sentinel

Sentinel Introduction

Sentinel is the official Redis high‑availability solution that can automatically fail over a master, monitor instances, and notify clients.

Key functions include Monitoring, Notification, Automatic failover, and Configuration provider.

Sentinel Configuration

Sentinel runs as a special‑mode Redis server. Example sentinel.conf:

// [monitor name] [ip] [port] [quorum]
sentinel monitor mymaster 127.0.0.1 6379 2
// master down after milliseconds
sentinel down-after-milliseconds mymaster 60000
// failover timeout
sentinel failover-timeout mymaster 180000
// parallel syncs
sentinel parallel-syncs mymaster 1

Start with Redis 2.8+: redis-sentinel sentinel.conf After start, Sentinel:

Every 10 s sends INFO to the monitored master.

Every 1 s PINGs all Redis servers including other Sentinels.

Every 2 s publishes its view of master/slave status.

It is recommended to run at least three Sentinel instances and require two votes for a failover.

Three Ways to Receive Failover Messages

Script Notification

Configure a notification script executed on failover (max 60 s).

sentinel notification-script mymaster /var/redis/notify.sh

Configure a client reconfiguration script after failover.

sentinel client-reconfig-script mymaster /var/redis/notifyReconfig.sh

Client Direct Subscription

Sentinel publishes events via Redis Pub/Sub. Clients subscribe to channels such as “+slave”. Message format:

<instance-type> <name> <ip> <port> @ <master-name> <master-ip> <master-port>

Example:

* // subscribe all
-sdown // message type
slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6381

Service‑Level Indirect Reception

Introduce an intermediate service that subscribes to Sentinel events and exposes an API for applications to receive callbacks, reducing coupling and improving scalability.

Application does not need to change when Sentinel is replaced.

Service can add watchdog threads for extra reliability.

Example API endpoint: http://127.0.0.1/redis/notify.api Service calls the API after detecting a state change:

httprequest.post("http://127.0.0.1/redis/notify.api");

Overall Design

The third method (service‑level indirect reception) is recommended. The diagram below illustrates the flow.

Conclusion

Various Sentinel notification types are documented in the official Redis docs. The author’s project uses the HRedis client (https://github.com/mushroomsir/HRedis). While ZooKeeper can be used for HA, Sentinel offers a low‑cost, extensible solution suitable for small teams.

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.

high availabilityConfigurationsentinelfailover
ITFLY8 Architecture Home
Written by

ITFLY8 Architecture Home

ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, 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.