Why replication provides redundancy in Redis - Performance Analysis
We want to understand how the work done by Redis changes when it copies data to other servers for safety.
How does copying data affect the time it takes as the data grows?
Analyze the time complexity of the following Redis replication commands.
SYNC
PSYNC <runid> <offset>
REPLCONF ACK <offset>
These commands help the main Redis server send data to its copies (replicas) to keep them updated.
Look at what repeats when Redis copies data:
- Primary operation: Sending data changes from the main server to each replica.
- How many times: Once for each replica, and continuously as data changes.
As the amount of data or number of replicas grows, the work to copy data grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 replicas | 10 times the data sent |
| 100 replicas | 100 times the data sent |
| 1000 replicas | 1000 times the data sent |
Pattern observation: The work grows directly with the number of replicas because each one needs its own copy.
Time Complexity: O(n)
This means the time to replicate grows in a straight line as you add more replicas.
[X] Wrong: "Replication time stays the same no matter how many replicas there are."
[OK] Correct: Each replica needs its own copy, so more replicas mean more work and more time.
Understanding how replication time grows helps you explain how systems keep data safe and available, a key skill in real-world database work.
"What if Redis used a single shared copy for all replicas instead of separate copies? How would the time complexity change?"