Why clustering provides horizontal scaling in Redis - Performance Analysis
We want to see how adding more servers in a Redis cluster affects the work done when handling data.
How does splitting data across servers change the time to process requests?
Analyze the time complexity of these Redis cluster commands.
CLUSTER INFO
SET key1 value1
SET key2 value2
GET key1
GET key2
This code shows simple commands where keys are stored and retrieved in a Redis cluster.
Look at what repeats when we add more keys and servers.
- Primary operation: Storing or retrieving a key on the correct server.
- How many times: Once per key, but keys are spread across servers.
As we add more keys, each server handles fewer keys because data is split.
| Input Size (n keys) | Approx. Operations per Server |
|---|---|
| 10 keys, 1 server | 10 operations |
| 100 keys, 5 servers | ~20 operations each |
| 1000 keys, 10 servers | ~100 operations each |
Pattern observation: Adding servers splits the work, so each server does less work even if total keys grow.
Time Complexity: O(n / k)
This means the work per server grows with the number of keys divided by the number of servers.
[X] Wrong: "Adding more servers always makes the system twice as fast regardless of data size."
[OK] Correct: Because if data is small, splitting it adds overhead. Also, network and coordination costs affect speed.
Understanding how clustering spreads work helps you explain scaling in real systems. It shows you can think about how adding resources changes performance.
What if we added more servers but kept the same number of keys? How would the time complexity per server change?
Practice
Solution
Step 1: Understand horizontal scaling meaning
Horizontal scaling means adding more machines to handle more work, not just improving one machine.Step 2: Connect clustering to horizontal scaling
Redis clustering splits data across many machines, so the system can handle more users and data by adding machines.Final Answer:
Because it adds more machines to share the load -> Option DQuick Check:
Horizontal scaling = adding machines [OK]
- Thinking clustering speeds up a single machine
- Confusing horizontal with vertical scaling
- Believing clustering compresses data
Solution
Step 1: Identify cluster creation commands
Redis uses special cluster commands like CLUSTER MEET to connect nodes and form a cluster.Step 2: Check other commands' purpose
SET and GET are for data operations, FLUSHALL clears data, not for clustering.Final Answer:
CLUSTER MEET -> Option AQuick Check:
Cluster setup uses CLUSTER MEET [OK]
- Choosing data commands like SET or GET
- Confusing FLUSHALL with cluster setup
- Not knowing cluster-specific commands
CLUSTER MEET 192.168.1.2 7001 CLUSTER MEET 192.168.1.3 7001
Solution
Step 1: Understand CLUSTER MEET command effect
CLUSTER MEET connects a new node to the cluster, allowing it to join and share data.Step 2: Check other options' validity
It does not replace nodes, disconnect cluster, or delete data by itself.Final Answer:
The new node joins the cluster and shares data load -> Option BQuick Check:
CLUSTER MEET adds node to cluster [OK]
- Thinking new node replaces old nodes
- Assuming cluster disconnects on adding nodes
- Believing data is deleted on node join
CLUSTER MEET, but the node does not join. What is the likely error?Solution
Step 1: Check network connectivity
If the new node IP is unreachable, it cannot join the cluster despite correct commands.Step 2: Validate other options
Different config or full cluster usually give errors; syntax errors cause command failure, not silent join failure.Final Answer:
The node IP address is unreachable -> Option AQuick Check:
Unreachable IP blocks cluster join [OK]
- Ignoring network issues
- Assuming syntax error without checking
- Believing cluster size limits node addition
Solution
Step 1: Understand data distribution in clustering
Redis cluster splits data and requests across all nodes to balance load.Step 2: Analyze effect of adding nodes
Adding nodes increases total capacity by sharing data and requests among more machines.Step 3: Eliminate wrong options
Data does not move only to new nodes, cluster does not merge nodes, and new nodes are not just backups.Final Answer:
Data and requests are split across 5 nodes, increasing capacity -> Option CQuick Check:
More nodes = more shared load = horizontal scaling [OK]
- Thinking new nodes only backup data
- Believing cluster merges nodes into one
- Assuming data moves only to new nodes
Ready to prove it?
Pass the test and this pattern moves unknown
