Lesson 18 — Load Balancing in Azure
Why Load Balancing Is Always in the Exam
Azure has four distinct load balancing products: Azure Load Balancer, Application Gateway, Azure Front Door, and Traffic Manager. They are not interchangeable — each solves a specific problem at a specific OSI layer, with different geographic scope. The AZ-104 exam consistently tests whether you can pick the right product for a given scenario, and whether you understand how they can be layered together.
Senior engineers in real Azure environments face this decision constantly. A mistake here — using a Basic Load Balancer instead of Standard, or an Application Gateway when Traffic Manager is needed — can mean production downtime, security exposure, or failed availability zone redundancy. This lesson gives you the complete decision model.
1. The Four Load Balancing Services
Each Azure load balancing service addresses a different combination of OSI layer, geographic scope, and protocol support:
| Service | OSI Layer | Scope | Protocol | WAF | SSL Termination | Primary Use Case |
|---|---|---|---|---|---|---|
| Azure Load Balancer | Layer 4 (TCP/UDP) | Regional | TCP, UDP | No | No | VM / VMSS traffic distribution within a region |
| Application Gateway | Layer 7 (HTTP/S) | Regional | HTTP, HTTPS, HTTP/2, WebSocket | Yes (WAF_v2) | Yes | Web apps needing URL routing, WAF, SSL offload |
| Azure Front Door | Layer 7 (HTTP/S) | Global | HTTP, HTTPS | Yes (Premium) | Yes | Global web apps with CDN, anycast routing, WAF |
| Traffic Manager | DNS-based (L3/4) | Global | Any (DNS only) | No | No | Global HA and failover including non-HTTP services |
2. Azure Load Balancer
Azure Load Balancer operates at Layer 4. It distributes inbound TCP and UDP flows across backend pool members based on a configurable hash algorithm. It does not inspect, decrypt, or modify the packet payload — it only sees IP addresses and ports.
SKUs — Standard vs. Basic
| Feature | Standard SKU | Basic SKU |
|---|---|---|
| Availability Zones | Zone-redundant and zonal frontends supported | Not supported |
| VMSS support | Yes | Yes (limited) |
| Backend pool size | Up to 1,000 instances | Up to 300 instances |
| Health probe protocols | TCP, HTTP, HTTPS | TCP, HTTP only |
| Secure by default (NSG required) | Yes — inbound blocked by default | No — open by default |
| SLA | 99.99% | No SLA |
| Status | Current — use this | Retiring September 2025 |
Core components
| Component | Description |
|---|---|
| Frontend IP configuration | Public IP (internet-facing) or private IP (internal load balancer). A Standard LB can have multiple frontends. |
| Backend pool | Set of VMs or VMSS instances that receive distributed traffic. Can span Availability Zones (Standard SKU). |
| Health probes | Periodic checks to determine if a backend is healthy. Unhealthy backends are removed from rotation. Probe source IP is always 168.63.129.16 — must be allowed in backend NSGs. |
| Load balancing rules | Map a frontend IP:port to a backend pool:port using a distribution algorithm (5-tuple hash by default). |
| Inbound NAT rules | Forward specific ports on the frontend IP to specific VMs — used for RDP/SSH access to individual backend VMs. |
| Outbound rules | Configure SNAT for backend pool VMs to reach the internet through the Load Balancer's public IP. Controls SNAT port allocation. |
Session persistence (sticky sessions)
By default, Azure Load Balancer uses a 5-tuple hash (source IP, source port, destination IP, destination port, protocol) to distribute traffic. For stateful applications that need a client to always hit the same backend:
| Mode | Hash inputs | Use case |
|---|---|---|
| None (default) | 5-tuple hash | Stateless workloads — best distribution |
| Client IP | Source IP (2-tuple) | Same client IP always hits same backend |
| Client IP and Protocol | Source IP + protocol (3-tuple) | Client with multiple protocols still sticky per protocol |
Internal Load Balancer (ILB)
When the frontend IP is a private IP within a VNet, the Load Balancer is an Internal Load Balancer. Use this to distribute traffic between tiers within a VNet — for example, from an application tier to a database tier, or in front of NVAs (Network Virtual Appliances) in a hub-spoke topology.
HA Ports rule
A special load balancing rule that balances all TCP/UDP ports simultaneously. Only available on Internal Load Balancers with Standard SKU. Used when NVAs must inspect traffic on all ports — configure an ILB with an HA Ports rule in front of a cluster of NVA VMs.
168.63.129.16. If your backend VMs have NSGs that do not allow inbound from this IP (or from the AzureLoadBalancer service tag), the health probe will fail and the backend will be marked unhealthy — it will receive no traffic even if the application is running perfectly. This is a very common misconfiguration.
3. Application Gateway
Application Gateway is a Layer 7 load balancer that understands HTTP and HTTPS. It can inspect the full HTTP request — URL path, host headers, query strings, cookies — and make routing decisions based on that content. This makes it dramatically more powerful than Azure Load Balancer for web application workloads.
Core components
| Component | Description |
|---|---|
| Frontend IP | Public or private IP. The entry point for all incoming requests. |
| Listeners | Define port, protocol (HTTP/HTTPS), and optionally hostname (for multi-site hosting). A basic listener accepts all traffic on a port; a multi-site listener routes based on Host header. |
| Rules | Basic rule: maps a listener to a single backend pool. Path-based rule: routes different URL paths (/api/*, /images/*) to different backend pools. |
| Backend pools | VMs, VMSS, App Service instances, IP addresses, or FQDNs. Different pools for different URL paths or hostnames. |
| HTTP settings | Protocol and port to use when forwarding to backends, cookie-based session affinity, connection draining, custom health probe configuration, request/response headers. |
| Health probes | HTTP/HTTPS probes that check backend health. Default probe uses the HTTP settings protocol/port; custom probes allow specific URL paths, status codes, and intervals. |
SSL/TLS handling modes
| Mode | Description | Use case |
|---|---|---|
| SSL termination | HTTPS decrypted at the gateway; traffic forwarded to backends over HTTP (unencrypted inside VNet) | Reduces CPU load on backends; certificate management centralised at gateway |
| End-to-end SSL | HTTPS decrypted at gateway, re-encrypted for backend communication | Compliance requirements that mandate encryption in transit throughout |
| SSL passthrough | TLS connection passed directly to backend — gateway does not decrypt | When the backend must see the original client certificate |
WAF — Web Application Firewall
Application Gateway WAF_v2 SKU includes an integrated WAF that inspects HTTP/S requests against OWASP Core Rule Sets (CRS). The WAF protects against the OWASP Top 10 vulnerabilities including SQL injection, cross-site scripting (XSS), and remote code execution attacks.
- Detection mode: logs violations but does not block traffic. Use for initial tuning.
- Prevention mode: actively blocks requests that match WAF rules.
- Custom rules: allow or deny based on IP ranges, geo-location, HTTP variables, or rate limits.
- Bot protection: built-in ruleset for known malicious bots.
SKUs
| SKU | WAF | Autoscaling | Zone redundancy |
|---|---|---|---|
| Standard_v2 | No | Yes | Yes |
| WAF_v2 | Yes (OWASP CRS + custom rules) | Yes | Yes |
| Standard_v1 / WAF_v1 | Limited (v1 only) | No | No |
Path-based routing example
Listener: HTTPS on port 443 for "app.contoso.com"
│
├─ /api/* → backend-pool-api (API VMs, port 8080)
├─ /images/* → backend-pool-storage (Azure Blob / CDN)
├─ /admin/* → backend-pool-admin (Admin VMs, with WAF custom rule)
└─ /* (default) → backend-pool-web (Web frontend VMs, port 80)
4. Azure Front Door
Azure Front Door is Microsoft's global Layer 7 load balancing service. It operates on Microsoft's global anycast network — users worldwide are routed to the nearest Microsoft PoP (Point of Presence), which then proxies the request to the origin. This dramatically reduces latency for geographically distributed users.
Key capabilities
- Global anycast routing: users connect to the nearest of Microsoft's 200+ edge PoPs globally
- L7 load balancing: HTTP/S routing to multiple regional backend origins
- SSL offload: TLS termination at the edge PoP, reducing latency
- WAF: OWASP CRS-based protection at global scale (Standard and Premium SKUs)
- Caching (CDN): static content cached at PoPs, reducing origin load
- Health probes to origins: detects unhealthy origins and routes around them
- URL rewrite and redirect: HTTP → HTTPS redirect, path manipulation
SKUs
| SKU | CDN | WAF | Private Link to Origins | Security Analytics |
|---|---|---|---|---|
| Standard | Yes | Yes (OWASP) | No | No |
| Premium | Yes | Yes (advanced + managed rulesets) | Yes | Yes |
Front Door vs. Application Gateway
Both are L7 load balancers with WAF. The key difference is scope:
- Application Gateway is regional — deploy one per region, routes traffic within that region.
- Front Door is global — single deployment routes users worldwide to the nearest regional backend (which may itself be behind an Application Gateway).
5. Traffic Manager
Traffic Manager is fundamentally different from the other three services. It does not proxy traffic — it only controls DNS resolution. When a client queries a Traffic Manager profile, Traffic Manager returns the IP of the "best" endpoint based on the configured routing method. The client then connects directly to that endpoint.
Routing methods
| Routing Method | Behaviour | Use Case |
|---|---|---|
| Priority | Route all traffic to the primary endpoint; fail over to secondary only if primary is unhealthy | Active/passive disaster recovery between regions |
| Weighted | Distribute traffic proportionally by weight (e.g. 90/10 or 50/50) | A/B testing, gradual migration, blue-green deployments |
| Performance | Route to the endpoint with the lowest latency to the client (based on client IP geolocation) | Global app — route each user to the nearest region for lowest latency |
| Geographic | Route traffic from specific countries, regions, or continents to designated endpoints | Data residency compliance — European users must be served from EU region |
| Multivalue | Return multiple healthy endpoints in a single DNS response | Client-side load balancing for IPv4/IPv6 endpoints |
| Subnet | Map specific client IP address ranges to specific endpoints | Serve different content to different network segments (e.g. corporate vs. consumer) |
Health probes
Traffic Manager continuously probes endpoint health using HTTP, HTTPS, or TCP checks. When an endpoint fails its health probe, Traffic Manager stops returning its IP in DNS responses — clients are routed to a healthy endpoint instead.
6. Decision Guide — Which Service to Use
The AZ-104 exam tests this decision tree repeatedly. Memorise the key differentiators:
Layering services — the enterprise pattern
These services are designed to be combined. A fully resilient global web application might use all four:
| Layer | Service | Responsibility |
|---|---|---|
| 1 (outermost) | Traffic Manager | Global DNS failover: route all traffic to East US; if East US is down, redirect to West Europe |
| 2 | Application Gateway (per region) | Regional L7 routing: URL-path routing to microservices, WAF protection, SSL offload |
| 3 | Azure Load Balancer (internal) | Internal L4 distribution: spread HTTP traffic across a pool of backend VMs behind Application Gateway |
| 4 (innermost) | VMs / VMSS | Application workload |
Check Your Understanding
Click any option to see immediate feedback. Answers reflect real Azure load balancing behaviour.
1. You are deploying a Virtual Machine Scale Set (VMSS) in a region with Availability Zones. You need the load balancer to distribute traffic across VMs in all three zones, with a 99.99% SLA and secure-by-default traffic rules. Which load balancer configuration is correct?
2. Your web application is deployed in a single Azure region. You need to route HTTP requests for /api/* to a pool of API VMs, and requests for /static/* to a storage-backed pool. You also need WAF protection. Which Azure service should you use?
3. You deploy Traffic Manager with Priority routing. The primary endpoint is in East US and the secondary is in West Europe. An engineer asks whether clients will instantly fail over when East US goes down. What is the accurate answer?
4. You deploy a Standard Azure Load Balancer with a backend pool of three VMs. One VM consistently appears unhealthy in the load balancer's backend health view, but you can verify that the application is running normally on that VM by connecting directly. The VM's NSG allows inbound on port 80 from the internet. What is the most likely cause?
168.63.129.16. If the VM's NSG does not have an inbound rule allowing this source IP (or the AzureLoadBalancer service tag), the health probe packets are dropped. The VM never responds, the Load Balancer marks it unhealthy, and it receives no traffic. The NSG rule must explicitly permit inbound from AzureLoadBalancer service tag on the probe port.5. Your company runs a global e-commerce platform with regional backends in East US, West Europe, and Southeast Asia. Users worldwide complain of high latency. You need to route each user to the nearest regional backend, provide DDoS + WAF protection at the edge, cache static assets globally, and avoid managing multiple CDN deployments. Which single Azure service best addresses all of these requirements?
6. Your company operates in the EU and is subject to GDPR data residency requirements: European users must have their requests processed only by EU-region backends, and North American users must only hit North American backends. Which Traffic Manager routing method satisfies this requirement?
Also read: Application Gateway overview, Azure Front Door overview, and Traffic Manager routing methods. The load balancing decision guide at learn.microsoft.com/en-us/azure/architecture/guide/technology-choices/load-balancing-overview is the definitive reference for the decision tree.
This lesson covered the four Azure load balancing services. Explore the architecture further:
- Walk me through configuring Application Gateway path-based routing with a WAF policy using Bicep.
- How does Azure Front Door handle origin failover, and what are the health probe configuration options?
- What is SNAT port exhaustion on Azure Load Balancer and how do outbound rules help prevent it?
- How do you migrate from Azure Basic Load Balancer to Standard Load Balancer without downtime?