Default VPC and subnets in GCP - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When creating a default VPC in Google Cloud, several subnets are automatically set up. We want to understand how the time to create these resources changes as the number of regions grows.
How does the work grow when more subnets are created across regions?
Analyze the time complexity of the following operation sequence.
# Create a default VPC network
gcloud compute networks create default --subnet-mode=auto
# Automatically creates one subnet per region
# Each subnet has a predefined IP range
# List all subnets in the default VPC
gcloud compute networks subnets list --filter="network=default"
This sequence creates a default VPC with one subnet in each region and lists them.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating one subnet per region.
- How many times: Once for each region where Google Cloud has a data center.
Each new region adds one subnet creation operation. So, if the number of regions doubles, the number of subnet creations doubles too.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 regions | 10 subnet creations |
| 100 regions | 100 subnet creations |
| 1000 regions | 1000 subnet creations |
Pattern observation: The number of operations grows directly with the number of regions.
Time Complexity: O(n)
This means the time to create the default VPC and its subnets grows linearly with the number of regions.
[X] Wrong: "Creating the default VPC is a single operation that takes the same time no matter how many regions exist."
[OK] Correct: Each region requires a separate subnet to be created, so more regions mean more work and more time.
Understanding how resource creation scales helps you design cloud infrastructure that grows smoothly. This skill shows you can think about costs and delays as systems get bigger.
"What if the default VPC used a single global subnet instead of one per region? How would the time complexity change?"
Practice
Solution
Step 1: Understand the Default VPC concept
The Default VPC is a network automatically created by GCP to help users start quickly without manual setup.Step 2: Identify its features
It includes one subnet in each region with default IP address ranges, ready for use.Final Answer:
A pre-made network with one subnet per region and default IP ranges -> Option DQuick Check:
Default VPC = Pre-made network with subnets [OK]
- Thinking Default VPC is a VM or storage
- Assuming you must create it manually
- Confusing it with custom networks
Solution
Step 1: Identify the command to list subnets
The command to list subnets requires 'compute networks subnets list' with a network filter.Step 2: Specify the Default VPC network
Using '--network=default' filters subnets belonging to the Default VPC.Final Answer:
gcloud compute networks subnets list --network=default -> Option AQuick Check:
List subnets in default network = gcloud compute networks subnets list --network=default [OK]
- Using 'networks list' which shows networks, not subnets
- Listing instances or storage buckets instead
- Omitting the network filter
Solution
Step 1: Calculate total IPs in a /20 subnet
A /20 subnet has 2^(32-20) = 4096 total IP addresses.Step 2: Subtract reserved IPs in GCP subnet
GCP reserves 5 IPs per subnet (network, gateway, broadcast, and two reserved), so usable IPs = 4096 - 5 = 4091.Final Answer:
4091 usable IP addresses -> Option BQuick Check:
/20 subnet usable IPs = 4091 [OK]
- Using total IPs without subtracting reserved ones
- Confusing subnet mask with number of IPs
- Ignoring GCP reserved IP addresses
Solution
Step 1: Identify the type of Default VPC
The Default VPC is an auto-mode VPC network where subnets are automatically created and managed by GCP.Step 2: Understand limitations
You cannot manually create additional subnets in an auto-mode VPC like the Default VPC.Step 3: Reason about the error cause
Trying to create a subnet with an IP range that overlaps an existing subnet in the Default VPC causes an error.Final Answer:
The IP range overlaps with an existing Default VPC subnet -> Option AQuick Check:
Subnet creation error due to overlapping IP range [OK]
- Thinking IP range overlap is not the cause
- Assuming Default VPC allows manual subnets like custom VPCs
- Forgetting to specify region or using invalid name (different errors)
Solution
Step 1: Understand custom VPC subnet creation
Custom VPCs allow you to define your own IP ranges and subnets per region.Step 2: Avoid IP range overlap
Assigning unique CIDR blocks per subnet prevents routing conflicts and follows best practices.Step 3: Evaluate other options
Default VPC cannot have overlapping subnets; multiple Default VPCs per project are not allowed; same IP ranges in one VPC cause conflicts.Final Answer:
Create a custom VPC and assign non-overlapping CIDR blocks for each subnet in different regions -> Option CQuick Check:
Custom VPC + unique CIDRs = Best practice [OK]
- Trying to add overlapping subnets to Default VPC
- Assuming multiple Default VPCs per project are possible
- Using same IP ranges in multiple subnets inside one VPC
