Replication strategies in DBMS Theory - Time & Space Complexity
Replication strategies in databases help copy data across servers to improve availability and reliability.
We want to understand how the time to replicate data grows as the amount of data increases.
Analyze the time complexity of this simple replication process.
-- Pseudocode for synchronous replication
BEGIN TRANSACTION;
INSERT INTO master_table VALUES (...);
FOR EACH replica IN replicas LOOP
SEND data TO replica;
WAIT for replica ACKNOWLEDGEMENT;
END LOOP;
COMMIT TRANSACTION;
This code inserts data into the master database and sends it to each replica, waiting for confirmation before finishing.
Look for repeated actions that affect time.
- Primary operation: Sending data and waiting for acknowledgement to each replica.
- How many times: Once per replica, so the number of replicas determines repetitions.
As the number of replicas grows, the time to complete replication grows roughly in direct proportion.
| Input Size (number of replicas) | Approx. Operations |
|---|---|
| 10 | 10 sends and waits |
| 100 | 100 sends and waits |
| 1000 | 1000 sends and waits |
Pattern observation: Doubling replicas roughly doubles the replication time.
Time Complexity: O(r)
This means the replication time grows linearly with the number of replicas.
[X] Wrong: "Replication time stays the same no matter how many replicas there are."
[OK] Correct: Each replica requires sending data and waiting, so more replicas mean more total time.
Understanding how replication time grows helps you design systems that stay fast and reliable as they scale.
What if replication was asynchronous and did not wait for acknowledgements? How would the time complexity change?