Why VPC provides network isolation in GCP - Performance Analysis
We want to understand how the work done by a Virtual Private Cloud (VPC) grows as more network resources are added.
Specifically, how does VPC keep networks separate and how does that affect the operations it performs?
Analyze the time complexity of creating firewall rules for network isolation in a VPC.
// Create a VPC network
resource "google_compute_network" "vpc_network" {
name = "example-vpc"
auto_create_subnetworks = false
}
// Create multiple firewall rules to isolate subnets
resource "google_compute_firewall" "firewall_rule" {
count = var.subnet_count
name = "firewall-rule-${count.index}"
network = google_compute_network.vpc_network.name
direction = "INGRESS"
allow = [{ protocol = "tcp", ports = ["80"] }]
source_ranges = [var.allowed_ip_ranges[count.index]]
}
This sequence creates a VPC and multiple firewall rules to control traffic, isolating network parts.
Look at what repeats as we add more subnets and rules.
- Primary operation: Creating firewall rules to control traffic.
- How many times: Once per subnet or network segment needing isolation.
Each new subnet adds a firewall rule to isolate it, so the work grows with the number of subnets.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 firewall rule creations |
| 100 | 100 firewall rule creations |
| 1000 | 1000 firewall rule creations |
Pattern observation: The number of operations grows directly with the number of subnets.
Time Complexity: O(n)
This means the work to maintain network isolation grows in a straight line as you add more network segments.
[X] Wrong: "Adding more subnets does not increase the work because the VPC handles isolation automatically without extra rules."
[OK] Correct: Each subnet usually needs its own firewall rules to isolate traffic, so more subnets mean more rules and more work.
Understanding how network isolation scales helps you design secure and efficient cloud networks, a key skill in cloud roles.
What if we used shared firewall rules for multiple subnets instead of one per subnet? How would the time complexity change?