Cluster failover in Redis - Time & Space Complexity
When a Redis cluster fails over, it switches the role of a replica to master to keep the system running.
We want to understand how the time to complete this failover changes as the cluster size grows.
Analyze the time complexity of the following Redis cluster failover commands.
CLUSTER FAILOVER
CLUSTER REPLICATE <new_master_node_id>
CLUSTER SETSLOT <slot> NODE <new_master_node_id>
CLUSTER ADDSLOTS <slot>
This snippet shows commands used during failover to promote a replica and update cluster slot ownership.
During failover, the main repeating operation is updating slot ownership across nodes.
- Primary operation: Assigning slots to the new master node.
- How many times: Once per slot that the failed master owned, which can be many.
As the number of slots to reassign grows, the number of operations grows roughly the same.
| Input Size (slots) | Approx. Operations |
|---|---|
| 10 | 10 slot updates |
| 100 | 100 slot updates |
| 1000 | 1000 slot updates |
Pattern observation: The time grows linearly with the number of slots reassigned.
Time Complexity: O(n)
This means the failover time increases in direct proportion to the number of slots that need to be reassigned.
[X] Wrong: "Failover time stays the same no matter how many slots are reassigned."
[OK] Correct: Each slot reassignment requires a command, so more slots mean more work and longer time.
Understanding how failover time scales helps you explain system reliability and responsiveness in real-world Redis clusters.
"What if the cluster used fewer slots but more nodes? How would that affect the failover time complexity?"