Questions
What is Redis Sentinel and how do you use it for high availability?
The Scenario
You are a database administrator at a social media company. You are responsible for a Redis database that is critical to the business.
You have set up replication to a secondary database to provide high availability, but you need a way to automatically handle failover if the master node goes down.
The Challenge
Explain what Redis Sentinel is and how you would use it to provide automatic failover for a Redis replica set. What are the key benefits of using Redis Sentinel?
A junior engineer might not be aware of Redis Sentinel. They might try to solve this problem by manually promoting a slave to be the new master, which would not be a very robust solution.
A senior engineer would know that Redis Sentinel is the perfect tool for this job. They would be able to explain what Redis Sentinel is and how to use it to provide automatic failover for a Redis replica set.
Step 1: Understand What Redis Sentinel Is
Redis Sentinel is a system that provides high availability for Redis. It can automatically detect if the master node is down and promote one of the slave nodes to be the new master.
Step 2: The Key Features of Redis Sentinel
| Feature | Description |
|---|---|
| Monitoring | Sentinel constantly monitors the health of the master and slave nodes. |
| Notification | Sentinel can notify you if there is a problem with one of the nodes. |
| Automatic Failover | Sentinel can automatically promote a slave to be the new master if the master goes down. |
| Configuration Provider | Sentinel acts as a source of authority for clients service discovery. |
Step 3: Set Up Redis Sentinel
Here’s how we can set up a simple Redis Sentinel configuration with one master and two slaves:
1. Configure the Sentinel servers:
Create a sentinel.conf file on each Sentinel server.
port 26379
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 10000
sentinel parallel-syncs mymaster 12. Start the Sentinel servers:
Start the Sentinel servers.
redis-sentinel /path/to/sentinel.conf3. Connect your application to Sentinel:
Your application should connect to the Sentinel servers instead of the Redis servers directly. The Sentinel servers will then provide your application with the address of the current master.
Practice Question
You have a three-node replica set and you want to be able to automatically promote a slave to be the new master if the master goes down. Which of the following would you use?