VNet peering for connectivity in Azure - Time & Space Complexity
When connecting two virtual networks using VNet peering, it's important to understand how the number of connections affects the work Azure does behind the scenes.
We want to know how the effort grows as we add more peerings.
Analyze the time complexity of the following operation sequence.
// Create VNet peering between two VNets
az network vnet peering create \
--name Peer1to2 \
--resource-group MyResourceGroup \
--vnet-name VNet1 \
--remote-vnet /subscriptions/{subscriptionId}/resourceGroups/MyResourceGroup/providers/Microsoft.Network/virtualNetworks/VNet2 \
--allow-vnet-access
// Create VNet peering from VNet2 back to VNet1
az network vnet peering create \
--name Peer2to1 \
--resource-group MyResourceGroup \
--vnet-name VNet2 \
--remote-vnet /subscriptions/{subscriptionId}/resourceGroups/MyResourceGroup/providers/Microsoft.Network/virtualNetworks/VNet1 \
--allow-vnet-access
This sequence sets up two-way peering between two virtual networks to enable connectivity.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating a VNet peering connection via Azure API.
- How many times: Twice per pair of VNets (one peering each direction).
Each new VNet added requires peering with existing VNets, doubling the number of peering connections needed.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 2 VNets | 2 peerings (one each direction) |
| 3 VNets | 6 peerings (each pair peered both ways) |
| 4 VNets | 12 peerings |
Pattern observation: The number of peering operations grows quickly as more VNets are connected, roughly proportional to the square of the number of VNets.
Time Complexity: O(n²)
This means that as you add more virtual networks, the number of peering connections you need grows much faster, roughly like the square of the number of networks.
[X] Wrong: "Adding one more VNet only adds one more peering connection."
[OK] Correct: Each new VNet must peer with all existing VNets, so the number of connections grows much faster than just one per new network.
Understanding how network connections scale helps you design cloud networks that stay manageable and efficient as they grow.
What if VNet peering allowed automatic transitive connectivity? How would the time complexity of setting up connections change?
Practice
Solution
Step 1: Understand VNet peering concept
VNet peering allows two virtual networks to communicate directly without going through the internet.Step 2: Identify the main use case
This direct communication is the primary purpose, enabling resource sharing securely within Azure.Final Answer:
To connect two virtual networks for direct communication -> Option AQuick Check:
VNet peering = direct network connection [OK]
- Confusing peering with VM backup
- Thinking peering speeds up app deployment
- Assuming peering is for traffic monitoring
Solution
Step 1: Review peering setup requirements
VNet peering requires configuration from both virtual networks to allow full communication.Step 2: Identify correct procedure
Creating peering from both VNets ensures bidirectional connectivity and proper routing.Final Answer:
Create peering from both VNets involved -> Option CQuick Check:
Peering setup = both sides configured [OK]
- Configuring peering only on one VNet
- Assuming peering is automatic on new VNets
- Looking for peering in subscription settings
Solution
Step 1: Understand VNet peering behavior
Peering connects VNets so resources can communicate directly, including ping (ICMP) traffic if allowed by NSGs.Step 2: Analyze the ping scenario
If no network security group blocks ICMP, ping from VM in VNetA to VM in VNetB will succeed due to peering.Final Answer:
The ping succeeds because peering allows direct communication -> Option DQuick Check:
Peering enables direct VM communication [OK]
- Assuming peering blocks ping by default
- Thinking VMs must be in same subnet to communicate
- Believing peering does not enable VNet communication
Solution
Step 1: Understand peering directionality
Peering must be created on both VNets for full bidirectional communication.Step 2: Analyze partial peering effect
With peering only from VNetA to VNetB, traffic flows from A to B but not from B to A.Final Answer:
Unidirectional communication from VNetA to VNetB only -> Option BQuick Check:
One-sided peering = one-way traffic [OK]
- Assuming peering is automatic both ways
- Expecting no communication at all
- Thinking peering creates full connection from one side
Solution
Step 1: Identify peering types and their use cases
Local VNet peering works within the same region; global VNet peering connects VNets across regions.Step 2: Choose peering for cross-region communication
Global VNet peering enables secure, low-latency communication between VNets in different Azure regions.Final Answer:
Global VNet peering -> Option AQuick Check:
Cross-region VNet peering = global peering [OK]
- Choosing local peering for different regions
- Confusing VPN Gateway with peering
- Selecting ExpressRoute which is for on-premises
Ready to prove it?
Pass the test and this pattern moves unknown
