Load balancing rules in Azure - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When setting up load balancing rules in Azure, it's important to know how the number of rules affects the system's work.
We want to understand how the time to apply or process these rules grows as we add more rules.
Analyze the time complexity of the following operation sequence.
# Create public IP
az network public-ip create --resource-group MyRG --name MyPublicIP --location eastus --sku Standard
# Create a load balancer with backend pool and frontend IP
az network lb create --name MyLB --resource-group MyRG --location eastus --public-ip-address MyPublicIP --backend-pool-name MyBackendPool
# Add multiple load balancing rules
for i in $(seq 1 $n); do
az network lb rule create --resource-group MyRG --lb-name MyLB --name "Rule$i" \
--protocol Tcp --frontend-port $((80 + i)) --backend-port $((80 + i)) --frontend-ip-name LoadBalancerFrontEnd --backend-pool-name MyBackendPool
done
This sequence creates one load balancer and then adds n load balancing rules, each directing traffic from a unique frontend port to a backend port.
- Primary operation: Creating each load balancing rule via the Azure CLI API call.
- How many times: Exactly n times, once per rule added.
Each new rule requires one API call to create it, so as the number of rules grows, the total calls grow at the same pace.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 calls to create rules |
| 100 | 100 calls to create rules |
| 1000 | 1000 calls to create rules |
Pattern observation: The number of operations grows directly with the number of rules added.
Time Complexity: O(n)
This means the time to set up load balancing rules grows linearly as you add more rules.
[X] Wrong: "Adding more rules happens instantly without extra time."
[OK] Correct: Each rule requires a separate API call and processing, so more rules mean more time.
Understanding how the number of load balancing rules affects setup time shows you can think about scaling and resource management clearly.
"What if we batch multiple rules in a single API call? How would the time complexity change?"
Practice
Solution
Step 1: Understand load balancing rules
Load balancing rules define how traffic is distributed from the frontend IP to backend servers.Step 2: Identify the main function
The main function is to spread incoming traffic evenly to avoid overloading one server.Final Answer:
To distribute incoming network traffic evenly across backend servers -> Option CQuick Check:
Load balancing rules = distribute traffic evenly [OK]
- Confusing load balancing with VM creation
- Thinking it stores data
- Assuming it tracks user activity
Solution
Step 1: Review Azure CLI syntax for load balancing rules
The correct parameter for frontend port is '--frontend-port' with a hyphen.Step 2: Compare options
Only --frontend-port 80 uses the exact correct syntax '--frontend-port 80'. Others have incorrect parameter names.Final Answer:
--frontend-port 80 -> Option AQuick Check:
Azure CLI frontend port = --frontend-port [OK]
- Using camelCase instead of hyphens
- Mixing words order in parameter
- Using incorrect parameter names
"frontendPort": 443,
"backendPort": 8443,
"protocol": "Tcp"
What happens when a user sends a TCP request to port 443 on the frontend IP?
Solution
Step 1: Understand frontend and backend ports in load balancing
The frontend port is where the client connects; the backend port is where the traffic is sent on backend servers.Step 2: Match the ports and protocol
Client connects to port 443 (frontend), traffic is forwarded to backend servers on port 8443 using TCP.Final Answer:
The request is forwarded to backend servers on port 8443 -> Option AQuick Check:
Frontend port 443 forwards to backend port 8443 [OK]
- Assuming frontend and backend ports must be the same
- Confusing TCP with UDP protocol
- Thinking request is blocked due to port difference
Solution
Step 1: Check role of health probes
Health probes monitor backend server health; without them, load balancer may not send traffic.Step 2: Identify misconfiguration
If health probe is missing or wrong, backend servers appear unhealthy, so traffic is blocked.Final Answer:
Health probe is missing or misconfigured -> Option DQuick Check:
Missing health probe blocks traffic [OK]
- Ignoring health probe setup
- Assuming backend servers are always healthy
- Overlooking frontend IP correctness
Solution
Step 1: Match frontend and backend ports with protocol
Frontend port 443 (HTTPS) forwards to backend port 8443 using TCP protocol, matching the requirement.Step 2: Configure health probe correctly
Health probe must check TCP on port 8443 to verify backend VM health before forwarding traffic.Step 3: Verify other options
Load balancing rule with frontendPort=8443, backendPort=443, protocol=Tcp; health probe on port 443 using Http swaps ports and uses HTTP probe incorrectly; Load balancing rule with frontendPort=443, backendPort=443, protocol=Udp; health probe on port 8443 using Tcp uses UDP protocol wrongly; Load balancing rule with frontendPort=443, backendPort=8443, protocol=Tcp; no health probe configured lacks health probe, risking traffic to unhealthy VMs.Final Answer:
Load balancing rule with frontendPort=443, backendPort=8443, protocol=Tcp; health probe on port 8443 using Tcp -> Option BQuick Check:
Correct ports, protocol, and health probe = Load balancing rule with frontendPort=443, backendPort=8443, protocol=Tcp; health probe on port 8443 using Tcp [OK]
- Swapping frontend and backend ports
- Using wrong protocol (UDP instead of TCP)
- Skipping health probe configuration
