Disaster recovery strategies in GCP - Time & Space Complexity
When planning disaster recovery in cloud systems, it's important to understand how the time to recover grows as the amount of data or resources increases.
We want to know how the recovery steps scale when more resources or data are involved.
Analyze the time complexity of restoring multiple virtual machines from snapshots in GCP.
for vm in vm_list:
snapshot = compute.snapshots().get(project=project_id, snapshot=vm.snapshot_name).execute()
operation = compute.instances().insert(
project=project_id,
zone=vm.zone,
body={
'name': vm.name,
'disks': [{'sourceSnapshot': snapshot['selfLink']}],
'machineType': vm.machine_type
}
).execute()
wait_for_operation(operation)
This sequence restores each VM by retrieving its snapshot and creating a new instance from it.
Look at what repeats for each VM being restored.
- Primary operation: Retrieving snapshot metadata and creating a VM instance from it.
- How many times: Once per VM in the list.
Each VM requires its own snapshot retrieval and instance creation, so the total time grows as more VMs are restored.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | About 10 snapshot gets and 10 instance creations |
| 100 | About 100 snapshot gets and 100 instance creations |
| 1000 | About 1000 snapshot gets and 1000 instance creations |
Pattern observation: The number of operations grows directly with the number of VMs to restore.
Time Complexity: O(n)
This means the recovery time increases in direct proportion to the number of virtual machines being restored.
[X] Wrong: "Restoring multiple VMs can be done in constant time because snapshots are ready to use."
[OK] Correct: Each VM requires separate API calls and resource creation, so the total time grows with the number of VMs.
Understanding how recovery steps scale helps you design better disaster recovery plans and shows you can think about system behavior as it grows.
"What if we restored all VMs in parallel instead of one by one? How would the time complexity change?"