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?"
Practice
Solution
Step 1: Understand disaster recovery purpose
Disaster recovery aims to keep systems available and data safe during failures or disasters.Step 2: Identify the main goal
The main goal is to maintain service uptime and data integrity despite problems.Final Answer:
To keep services running during unexpected problems -> Option BQuick Check:
Disaster recovery = keep services safe [OK]
- Confusing disaster recovery with cost saving
- Thinking it improves speed or UI
- Ignoring service availability
Solution
Step 1: Identify backup storage service
Backups need durable, scalable storage. Google Cloud Storage is designed for this.Step 2: Exclude compute and messaging services
Compute Engine and Kubernetes Engine run workloads, Pub/Sub handles messaging, not backups.Final Answer:
Google Cloud Storage -> Option DQuick Check:
Backup storage = Cloud Storage [OK]
- Choosing compute services for backup storage
- Confusing messaging service with storage
- Not knowing Cloud Storage purpose
resource "google_compute_instance" "primary" {
name = "primary-instance"
zone = "us-central1-a"
machine_type = "e2-medium"
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
}
resource "google_compute_instance" "backup" {
name = "backup-instance"
zone = "us-central1-b"
machine_type = "e2-medium"
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
}
What is the main benefit of this configuration for disaster recovery?Solution
Step 1: Analyze instance zones
The two instances are in different zones (us-central1-a and us-central1-b), which protects against zone failure.Step 2: Identify disaster recovery benefit
Having instances in separate zones improves availability and fault tolerance during disasters.Final Answer:
It creates two instances in different zones to improve availability -> Option AQuick Check:
Multi-zone instances = better availability [OK]
- Assuming cost reduction is main goal
- Thinking data backup happens automatically
- Confusing network speed with disaster recovery
Solution
Step 1: Understand snapshot storage risk
If snapshots are stored only in the same zone, a zone failure can destroy both primary data and backups.Step 2: Identify cause of missing snapshots
Storing snapshots in the same zone risks losing them during a disaster affecting that zone.Final Answer:
Snapshots were stored in the same zone as the primary data -> Option AQuick Check:
Backups must be in different zones [OK]
- Ignoring backup location importance
- Assuming encryption or disk choice caused failure
- Not scheduling snapshots regularly
Solution
Step 1: Identify recovery time objective (RTO)
Recovery within minutes requires fast failover and minimal data loss.Step 2: Evaluate strategies for fast recovery
Multi-region deployment with automated failover and continuous replication ensures quick switch and up-to-date data.Step 3: Compare with other options
Single-zone or single-region with manual backups are slower and risk data loss; weekly or monthly backups are too infrequent.Final Answer:
Use multi-region deployment with automated failover and continuous data replication -> Option CQuick Check:
Fast recovery needs multi-region + automation [OK]
- Choosing single-zone or single-region for critical apps
- Relying on manual backups for quick recovery
- Ignoring continuous data replication
Ready to prove it?
Pass the test and this pattern moves unknown
