Cluster architecture in Redis - Time & Space Complexity
When using Redis cluster architecture, it is important to understand how the time to complete operations changes as the cluster grows.
We want to know how the number of nodes affects the speed of commands across the cluster.
Analyze the time complexity of accessing a key in a Redis cluster.
# Client sends command to cluster
# Cluster uses hash slot to find node
# Node executes command locally
# Result returned to client
# Example:
GET mykey
This snippet shows a simple key lookup in a Redis cluster, where the cluster routes the command to the correct node based on the key.
Look for repeated steps that affect time.
- Primary operation: Hash slot calculation and node lookup.
- How many times: Once per command to find the right node.
As the number of nodes increases, the cluster must find the right node for the key.
| Number of Nodes (n) | Approx. Operations |
|---|---|
| 3 | 1 hash calculation + 1 node lookup |
| 10 | 1 hash calculation + 1 node lookup |
| 100 | 1 hash calculation + 1 node lookup |
Pattern observation: The number of operations stays about the same regardless of cluster size because the hash slot calculation is constant time and node lookup is direct.
Time Complexity: O(1)
This means the time to find and access a key in the cluster does not grow as the cluster gets bigger.
[X] Wrong: "More nodes means slower key lookups because the cluster has to check many nodes."
[OK] Correct: The cluster uses a fixed hash slot to directly find the node, so it does not check nodes one by one.
Understanding how Redis cluster keeps key lookups fast helps you explain distributed system design clearly and confidently.
What if the cluster used a linear search to find the node instead of a hash slot? How would the time complexity change?