Subnet modes (auto, custom) in GCP - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When creating networks in GCP, subnet modes control how many subnetworks are made automatically or manually.
We want to know how the number of subnetworks affects the work GCP does behind the scenes.
Analyze the time complexity of creating subnetworks in different modes.
# Create a network in auto mode
gcloud compute networks create my-auto-network --subnet-mode=auto
# Create a network in custom mode
gcloud compute networks create my-custom-network --subnet-mode=custom
# Add subnets manually in custom mode
for i in {1..n}; do
gcloud compute networks subnets create subnet-$i --network=my-custom-network --region=us-central1 --range=10.0.$i.0/24
done
This sequence shows creating a network with automatic subnet creation versus manual subnet creation one by one.
Look at what actions happen multiple times.
- Primary operation: Creating subnetworks (API calls to create subnets)
- How many times: In auto mode, subnets are created once automatically for each region; in custom mode, each subnet creation is a separate call repeated n times.
As the number of subnetworks (n) increases, the number of subnet creation calls grows.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 subnet creation calls in custom mode; 1 in auto mode |
| 100 | 100 subnet creation calls in custom mode; 1 in auto mode |
| 1000 | 1000 subnet creation calls in custom mode; 1 in auto mode |
Pattern observation: Custom mode scales linearly with the number of subnets; auto mode does not increase calls with subnet count.
Time Complexity: O(n)
This means the work grows directly with how many subnets you create manually in custom mode.
[X] Wrong: "Creating many subnets in custom mode is as fast as auto mode because GCP handles it."
[OK] Correct: Each subnet creation is a separate action, so more subnets mean more work and time.
Understanding how resource creation scales helps you design efficient cloud networks and explain your choices clearly.
"What if we batch subnet creations in custom mode using scripts or APIs? How would the time complexity change?"
Practice
auto subnet mode in GCP?Solution
Step 1: Understand auto subnet mode behavior
In auto mode, GCP automatically creates subnets in every region with default IP ranges.Step 2: Compare with other modes
Unlike custom mode, auto mode does not require manual subnet creation or IP range assignment.Final Answer:
Subnets are automatically created in all regions with predefined IP ranges. -> Option AQuick Check:
Auto mode = automatic subnet creation [OK]
- Thinking auto mode requires manual subnet creation
- Assuming only one subnet is created
- Believing subnets have no IP ranges assigned
Solution
Step 1: Identify command to create a subnet
The command to create a subnet isgcloud compute networks subnets createwith network and IP range specified.Step 2: Check option correctness
gcloud compute networks subnets create my-subnet --network=my-network --range=10.0.0.0/24 correctly uses the subnet creation command with network and IP range parameters.Final Answer:
gcloud compute networks subnets create my-subnet --network=my-network --range=10.0.0.0/24 -> Option DQuick Check:
Subnet creation uses 'networks subnets create' with range [OK]
- Using 'networks create' to create subnets
- Missing the --range parameter for IP range
- Confusing network and subnet names
subnet-a: 10.1.0.0/16subnet-b: 10.2.0.0/16What happens if you try to create a third subnet with IP range
10.1.128.0/17?Solution
Step 1: Check IP range overlap
Subnet-a uses 10.1.0.0/16 which covers 10.1.0.0 to 10.1.255.255. The new subnet 10.1.128.0/17 overlaps this range.Step 2: Understand subnet creation rules
GCP does not allow overlapping IP ranges in subnets within the same VPC network.Final Answer:
Creation fails due to overlapping IP ranges with subnet-a. -> Option CQuick Check:
Overlapping IP ranges cause subnet creation failure [OK]
- Assuming subnets can overlap IP ranges
- Thinking GCP auto-adjusts overlapping ranges
- Believing traffic is blocked but subnet created
Solution
Step 1: Understand custom subnet mode requirements
In custom mode, subnets must be created manually before deploying resources.Step 2: Check VM deployment dependency
VMs require a subnet to get an IP address; without subnets, deployment fails.Final Answer:
The VM deployment fails because no subnet exists in the network. -> Option BQuick Check:
Custom mode needs subnets before VM deployment [OK]
- Assuming auto subnet creation in custom mode
- Thinking VM can deploy without internal IP
- Believing VM deploys but is unreachable
Solution
Step 1: Identify requirement for specific IP ranges
You want control over IP ranges, so automatic default ranges won't work.Step 2: Choose subnet mode matching control needs
Custom mode allows manual subnet creation with chosen IP ranges per region.Step 3: Eliminate incorrect options
Auto mode does not allow choosing IP ranges; it creates default subnets automatically.Final Answer:
Custom mode, because it lets you manually create subnets with specific IP ranges in each region. -> Option AQuick Check:
Custom mode = manual subnet creation with chosen IP ranges [OK]
- Confusing auto mode as allowing custom IP ranges
- Thinking auto mode subnets can be edited after creation
- Believing custom mode auto-creates subnets
