Synchronization process in Redis - Time & Space Complexity
When Redis synchronizes data between a master and a replica, it copies data to keep them the same.
We want to know how the time needed grows as the data size grows.
Analyze the time complexity of the following Redis synchronization commands.
SYNC
# Master sends full dataset to replica
# Replica receives and loads data
This process copies all data from the master to the replica to keep them synchronized.
Look for repeated actions in the synchronization.
- Primary operation: Sending each data item from master to replica.
- How many times: Once for every item stored in the database.
As the number of data items grows, the time to send all data grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 data sends |
| 100 | 100 data sends |
| 1000 | 1000 data sends |
Pattern observation: The time grows directly with the number of data items.
Time Complexity: O(n)
This means the time to synchronize grows in direct proportion to the amount of data.
[X] Wrong: "Synchronization time stays the same no matter how much data there is."
[OK] Correct: Because every data item must be sent, more data means more time.
Understanding how synchronization time grows helps you explain system behavior clearly and shows you can think about real-world data handling.
"What if Redis used incremental synchronization instead of full sync? How would the time complexity change?"