0
0
GCPcloud~5 mins

Disaster recovery strategies in GCP - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Disaster recovery strategies
O(n)
Understanding Time 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.

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

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
10About 10 snapshot gets and 10 instance creations
100About 100 snapshot gets and 100 instance creations
1000About 1000 snapshot gets and 1000 instance creations

Pattern observation: The number of operations grows directly with the number of VMs to restore.

Final Time Complexity

Time Complexity: O(n)

This means the recovery time increases in direct proportion to the number of virtual machines being restored.

Common Mistake

[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.

Interview Connect

Understanding how recovery steps scale helps you design better disaster recovery plans and shows you can think about system behavior as it grows.

Self-Check

"What if we restored all VMs in parallel instead of one by one? How would the time complexity change?"