Sentinel architecture in Redis - Time & Space Complexity
When using Redis Sentinel, it is important to understand how the system reacts as the number of monitored Redis instances grows.
We want to know how the time to detect failures and perform failover changes as we add more Redis servers.
Analyze the time complexity of the Sentinel monitoring and failover process.
# Sentinel monitors multiple Redis masters
SENTINEL MONITOR mymaster 127.0.0.1 6379 2
# Sentinel periodically pings each master and its replicas
PING
# If master is down, Sentinel starts failover
SENTINEL FAILOVER mymaster
# Sentinel votes among other Sentinels to elect new master
SENTINEL get-master-addr-by-name mymaster
This code shows Sentinel commands involved in monitoring and failover of Redis masters.
Sentinel continuously performs checks and coordination steps.
- Primary operation: Periodic health checks (PING) to each monitored Redis instance.
- How many times: Once per instance every few seconds, repeated indefinitely.
- Additional operation: Voting among Sentinels during failover, involving communication with other Sentinels.
As the number of Redis masters and replicas increases, Sentinel must ping each one regularly.
| Input Size (number of Redis instances) | Approx. Operations per Check Cycle |
|---|---|
| 10 | 10 pings |
| 100 | 100 pings |
| 1000 | 1000 pings |
Pattern observation: The number of operations grows directly with the number of Redis instances monitored.
Time Complexity: O(n)
This means the time Sentinel spends checking and managing Redis servers grows linearly as you add more servers.
[X] Wrong: "Sentinel's monitoring time stays the same no matter how many Redis instances it watches."
[OK] Correct: Sentinel must ping each instance regularly, so more instances mean more checks and more time spent.
Understanding how monitoring systems scale helps you design reliable and efficient distributed systems.
What if Sentinel used a smarter way to group health checks instead of pinging each instance individually? How would the time complexity change?
Practice
Solution
Step 1: Understand Sentinel's role
Redis Sentinel monitors Redis servers to detect failures.Step 2: Identify Sentinel's key feature
It automatically switches to a backup server if the main one fails, ensuring availability.Final Answer:
To monitor Redis servers and automatically handle failover -> Option CQuick Check:
Sentinel = automatic failover [OK]
- Confusing Sentinel with data storage
- Thinking Sentinel provides UI
- Assuming Sentinel compresses data
Solution
Step 1: Recall Redis Sentinel startup command
The correct command to start Sentinel isredis-sentinelfollowed by the config file.Step 2: Check each option
redis-sentinel /path/to/sentinel.conf matches the correct syntax; others are invalid commands or flags.Final Answer:
redis-sentinel /path/to/sentinel.conf -> Option AQuick Check:
Sentinel starts with redis-sentinel command [OK]
- Using redis-server with --sentinel flag
- Trying to start Sentinel via redis-cli
- Using non-existent redis-start command
mymaster, what will the command redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster return?Solution
Step 1: Understand the command purpose
The command queries Sentinel on port 26379 for the address of the master named 'mymaster'.Step 2: Identify expected output
It returns the IP and port of the current master server Sentinel monitors.Final Answer:
The IP and port of the current master server -> Option BQuick Check:
get-master-addr-by-name returns master address [OK]
- Confusing master address with slave list
- Expecting config file path as output
- Assuming command is invalid
Solution
Step 1: Understand failover conditions
Sentinel requires a quorum of Sentinel instances to agree before failover.Step 2: Analyze the cause of no failover
If quorum is not reached, Sentinel will not promote a slave to master.Final Answer:
Sentinel quorum is not reached due to insufficient Sentinel instances -> Option AQuick Check:
Failover needs quorum agreement [OK]
- Blaming persistence for failover
- Assuming Redis version blocks Sentinel
- Thinking SSL affects failover
Solution
Step 1: Understand quorum setting
The quorum setting defines the minimum number of Sentinels that must agree to start failover.Step 2: Apply quorum to the cluster
With quorum set to 3, at least 3 Sentinel nodes must agree to trigger failover.Final Answer:
At least 3 Sentinel nodes must agree -> Option DQuick Check:
Quorum = minimum agreeing Sentinels [OK]
- Thinking only 1 Sentinel is enough
- Assuming all Sentinels must agree
- Confusing quorum with total Sentinel count
Ready to prove it?
Pass the test and this pattern moves unknown
