Failover manual process in Redis - Time & Space Complexity
When manually handling failover in Redis, it is important to understand how the time to complete the process changes as the system size grows.
We want to know how the steps involved scale when more data or nodes are involved.
Analyze the time complexity of the following manual failover commands.
# Step 1: Promote a replica to master
SLAVEOF NO ONE
# Step 2: Reconfigure other replicas to follow new master
SLAVEOF <new_master_ip> <new_master_port>
# Step 3: Update clients to connect to new master
# (outside Redis, assumed manual or automated)
This snippet shows the basic commands to manually promote a replica and reconfigure other replicas during failover.
Look for repeated steps or commands that affect time.
- Primary operation: Reconfiguring each replica with
SLAVEOFto point to the new master. - How many times: Once per replica, so the number of replicas determines how many commands run.
The time to complete failover grows as you have more replicas to update.
| Number of Replicas (n) | Approx. Commands Sent |
|---|---|
| 2 | 2 |
| 10 | 10 |
| 100 | 100 |
Pattern observation: The number of commands grows directly with the number of replicas, so more replicas mean more time to reconfigure.
Time Complexity: O(n)
This means the time to complete manual failover grows linearly with the number of replicas you need to update.
[X] Wrong: "Failover time stays the same no matter how many replicas there are."
[OK] Correct: Each replica must be told to follow the new master, so more replicas mean more commands and more time.
Understanding how manual failover scales helps you show you know how system size affects recovery time, a useful skill for real-world database management.
"What if we automated the reconfiguration of replicas in parallel? How would that change the time complexity?"