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?