Azure Load Balancer Overview
Complete the full lesson to earn 25 points — 50 with Pro
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks, the wait, and see fewer ads — read each lesson on a single page with Pro
Lesson: Azure Load Balancer Overview
Introduction: The Backbone of High Availability
When you build applications in the cloud, the most significant challenge you face is scaling to meet user demand while ensuring that your service remains available even when individual components fail. If you run your application on a single virtual machine, you have a single point of failure. If that machine crashes, your entire application goes offline. This is where load balancing becomes essential.
An Azure Load Balancer acts as the traffic cop for your network. It sits in front of your backend servers and distributes incoming network traffic across multiple instances. By doing this, it ensures that no single server becomes overwhelmed, which improves the performance of your application. More importantly, it provides high availability. If one of your servers stops responding, the load balancer detects the failure and stops sending traffic to that specific instance, rerouting it to the healthy servers instead.
Understanding how to design and implement routing through Azure Load Balancer is a fundamental skill for any cloud engineer. It is not just about connecting machines; it is about building a resilient architecture that can withstand outages, handle traffic spikes, and provide a consistent experience for the end user. In this lesson, we will explore the mechanics of Azure Load Balancer, how it fits into the broader Azure networking ecosystem, and how you can configure it to meet the needs of your production workloads.
What is Azure Load Balancer?
Azure Load Balancer is a Layer 4 load balancer. This means it operates at the transport layer of the OSI model, handling TCP and UDP traffic. When a packet arrives, the load balancer uses a hash-based algorithm to determine which backend server should receive it. This hash is calculated based on the source IP, source port, destination IP, destination port, and protocol.
Because it operates at Layer 4, it is incredibly fast and efficient. It does not inspect the contents of the HTTP request (like a Layer 7 Application Gateway would). Instead, it focuses on the rapid, reliable delivery of packets. This makes it an ideal choice for high-performance applications, gaming servers, and internal service-to-service communication where low latency is a priority.
Callout: Layer 4 vs. Layer 7 Balancing A common point of confusion is knowing when to use Azure Load Balancer versus Azure Application Gateway. Azure Load Balancer is a Layer 4 device, meaning it is protocol-agnostic regarding the application content. It is fast, inexpensive, and handles massive volumes of traffic. Azure Application Gateway is a Layer 7 device that understands HTTP/HTTPS. It can route traffic based on URL paths, hostnames, and cookies, and it provides web application firewall capabilities. Choose Load Balancer for raw performance and non-HTTP traffic; choose Application Gateway for complex web routing.
Key Components of Azure Load Balancer
To effectively implement a load balancer, you must understand its constituent parts. These components work together to ensure traffic flows correctly from the internet (or an internal network) to your backend resources.
1. Frontend IP Configuration
This is the entry point for your traffic. You can configure a public IP address if your load balancer needs to be accessible from the internet, or a private IP address if it is only meant for internal traffic within your virtual network. You can associate multiple frontend IPs with a single load balancer, which is useful if you need to host multiple services on the same set of backend servers.
2. Backend Pool
The backend pool is the group of resources (usually virtual machines or virtual machine scale sets) that will process the incoming traffic. When you add a virtual machine to a backend pool, the load balancer begins monitoring its health.
3. Health Probes
A health probe is a background process that checks the status of your backend servers. You configure the probe to check a specific port and protocol (TCP, HTTP, or HTTPS) at a regular interval. If a probe fails a specific number of times, the load balancer marks that server as "unhealthy" and stops sending traffic to it. Once the server passes the probe again, it is automatically added back into rotation.
4. Load Balancing Rules
Rules define how the traffic is distributed. A rule maps a specific frontend IP and port to a backend port. For example, you might create a rule that says "all traffic arriving on port 80 at the frontend IP should be sent to port 80 on all machines in the backend pool."
5. Inbound NAT Rules
If you need to connect to a specific virtual machine in your backend pool directly (for example, via SSH or RDP), you use inbound NAT rules. This allows you to route traffic from a specific port on the frontend IP to a specific port on a specific backend instance.
Step-by-Step: Implementing an Azure Load Balancer
Let’s walk through the process of setting up a basic public load balancer using the Azure CLI. This approach is standard practice for infrastructure-as-code deployments.
Step 1: Create the Load Balancer
First, you need to create the resource itself. You must define the SKU—Standard is the recommended choice for production environments.
# Create the load balancer
az network lb create \
--resource-group MyResourceGroup \
--name MyLoadBalancer \
--sku Standard \
--public-ip-address MyPublicIP \
--frontend-ip-name MyFrontendIP \
--backend-pool-name MyBackendPool
Step 2: Configure the Health Probe
The health probe is vital. Without it, the load balancer cannot know if your backend servers are actually capable of processing requests.
# Create a health probe that checks port 80
az network lb probe create \
--resource-group MyResourceGroup \
--lb-name MyLoadBalancer \
--name MyHealthProbe \
--protocol tcp \
--port 80
Step 3: Define the Load Balancing Rule
Now, you link the frontend, the backend, and the probe together.
# Create the rule
az network lb rule create \
--resource-group MyResourceGroup \
--lb-name MyLoadBalancer \
--name MyLoadBalancingRule \
--protocol tcp \
--frontend-port 80 \
--backend-port 80 \
--frontend-ip-name MyFrontendIP \
--backend-pool-name MyBackendPool \
--probe-name MyHealthProbe
Step 4: Add Virtual Machines to the Backend Pool
Finally, you associate your virtual machines (or their network interfaces) with the backend pool. This is the step that actually puts the machines into the line of fire for incoming traffic.
Note: Ensure your virtual machines are in the same region and virtual network as the load balancer. They must also have a network security group (NSG) rule that allows traffic from the load balancer.
Understanding Traffic Distribution Algorithms
Azure Load Balancer uses a specific algorithm to ensure traffic is distributed predictably. The default is the Five-Tuple Hash.
The five-tuple consists of:
- Source IP
- Source Port
- Destination IP
- Destination Port
- Protocol
By hashing these five elements, the load balancer ensures that all packets from a specific client session are sent to the same backend server. This is critical for applications that maintain state (session persistence). If you need to ensure that a client always hits the same server, you can configure "Session Persistence" to just the Source IP, or Source IP and Protocol.
| Distribution Mode | Description | Best Use Case |
|---|---|---|
| None (Default) | Five-tuple hash (Source IP, Source Port, Dest IP, Dest Port, Protocol) | General web traffic, stateless services |
| Client IP | Two-tuple hash (Source IP, Dest IP) | When you need to ensure a client session stays on the same server |
| Client IP & Protocol | Three-tuple hash (Source IP, Dest IP, Protocol) | Advanced scenarios requiring strict session affinity |
Best Practices and Industry Standards
Implementing a load balancer is only half the battle. Maintaining it correctly is what ensures long-term stability.
Use Standard SKU
Always use the Standard SKU for the load balancer. The Basic SKU is deprecated for many scenarios and lacks the security and performance features of the Standard version. Standard SKU load balancers are secure by default, meaning they block all inbound traffic unless explicitly allowed by a network security group rule.
Configure Health Probes Correctly
A common mistake is configuring a probe that is too sensitive or not sensitive enough. If your probe interval is too short, a minor network jitter could mark a healthy server as unhealthy. If it is too long, users might experience a significant outage before the load balancer catches the failure. A 5-15 second interval is usually a good starting point.
Use Virtual Machine Scale Sets (VMSS)
If you are using Azure Load Balancer with VMs, consider using Virtual Machine Scale Sets. VMSS allows you to automatically add or remove backend instances based on CPU usage or other metrics. When a new VM is spun up by the scale set, it is automatically added to the Load Balancer backend pool, reducing the need for manual intervention.
Distribute Across Availability Zones
If your application requires high availability, do not put all your backend servers in a single data center. Use Availability Zones. You can deploy a Zone-Redundant Load Balancer that spreads traffic across multiple physical locations within an Azure region. If one entire zone goes down, your load balancer continues to route traffic to the remaining zones.
Warning: Port Exhaustion If your backend servers make many outbound connections (e.g., calling external APIs), you might run into SNAT (Source Network Address Translation) port exhaustion. This happens when the load balancer runs out of available ports to map traffic. To avoid this, use a NAT Gateway or scale your backend pool appropriately to provide more outbound capacity.
Common Pitfalls and Troubleshooting
Even with a perfect setup, issues can arise. Here is how to handle the most common problems.
1. The "Probe Failure" Loop
If your health probes are failing, your load balancer will effectively stop sending traffic, leading to a total outage. First, check your Network Security Group (NSG) rules. Ensure you are allowing traffic from the Azure Load Balancer service tag (IP address 168.63.129.16) to your backend VMs. This is the IP address used by the Azure platform to perform health probes.
2. Misconfigured Backend Port
A frequent error is mismatching the frontend and backend ports. If your application is listening on port 8080, but your load balancer rule is pointing to port 80, the health probe will fail (or the traffic will reach the server but be ignored). Always verify the application configuration matches the load balancer rule.
3. Lack of Session Affinity
If your application requires users to log in and stay logged in, and you find that users are being "logged out" randomly, you likely need to configure session persistence. Without it, the load balancer might send a user to a different server for every request, and if the servers don't share session state, the user will be forced to re-authenticate.
4. Ignoring Outbound Connectivity
Many engineers forget that the Standard Load Balancer does not provide default outbound connectivity. If your backend VMs need to reach the internet (e.g., to download updates), you must either assign a public IP directly to the VM (not recommended), use a NAT Gateway, or configure the Load Balancer to provide an outbound rule.
Deep Dive: The Role of SNAT
When you use a Standard Load Balancer, it provides outbound connectivity for your backend instances using a process called SNAT. The load balancer translates the private IP addresses of your VMs into the public IP address of the load balancer frontend.
However, each public IP address has a limited number of ports available for these connections (64,000 to be exact). If your application is very busy, you can exhaust these ports. You can mitigate this by:
- Adding multiple frontend IP addresses to the load balancer.
- Using a NAT Gateway, which is much more efficient at handling outbound traffic than the default SNAT provided by the load balancer.
- Monitoring the "SNAT Connection Count" and "SNAT Connection Failures" metrics in Azure Monitor to proactively scale your resources.
Security Considerations
Azure Load Balancer is a secure-by-default service. When you use the Standard SKU, the backend instances are not exposed to the internet until you explicitly define a Network Security Group (NSG) rule to allow that traffic.
Principle of Least Privilege
Only open the specific ports required for your application. If your application only needs port 443 (HTTPS), do not open port 80. If you are using administrative ports like 3389 (RDP) or 22 (SSH), use a Bastion host or a VPN instead of exposing them through the load balancer.
Integration with Azure Firewall
For even higher security, place an Azure Firewall in front of your Load Balancer or use the Load Balancer to feed traffic into a set of virtual appliances. This allows you to inspect traffic at the application layer before it even hits your load-balanced backend pool.
Monitoring and Diagnostics
You cannot manage what you cannot measure. Azure provides excellent tooling to monitor the health of your load balancer.
Azure Monitor Metrics
You should create alerts for the following metrics:
- Data Path Availability: This is the most important metric. If it drops below 100%, it means your users are experiencing packet loss.
- Health Probe Status: Track the number of failed probes. A spike in this metric indicates that your backend servers are struggling.
- Byte Count: Monitor the volume of traffic to ensure you are not hitting bandwidth limits.
Azure Resource Graph
You can use the Azure Resource Graph to audit your load balancer configurations across your entire subscription. This is useful for ensuring that all load balancers in your environment are using the Standard SKU and have proper health probes configured.
Comparison: Load Balancer vs. Other Azure Routing Services
To be a true expert, you must know when not to use the Load Balancer.
| Service | Type | Use Case |
|---|---|---|
| Azure Load Balancer | Layer 4 | High-performance, low-latency, non-HTTP traffic. |
| Application Gateway | Layer 7 | Web traffic, URL routing, WAF, SSL termination. |
| Azure Front Door | Layer 7 (Global) | Global distribution, content delivery, DDoS protection. |
| Traffic Manager | DNS-based | Routing based on geography or performance across regions. |
If you are building a global web application, you might use Front Door at the edge to handle global traffic, which then routes to an Application Gateway in each region for SSL termination and WAF, which finally routes to a Load Balancer for internal service communication. Understanding this "layered" approach is the hallmark of a senior cloud architect.
Practical Example: Configuring a Highly Available Web Service
Imagine you are deploying a web service that needs to be highly available. Here is the architecture you should aim for:
- Virtual Network: Create a VNet with at least two subnets.
- VM Scale Set: Deploy your web servers into a Scale Set spread across three Availability Zones.
- Load Balancer: Deploy a Standard Load Balancer with a zone-redundant public IP.
- Backend Pool: Add the VM Scale Set to the backend pool.
- Health Probe: Configure an HTTP probe to hit a
/healthendpoint on your web server. - NSG: Create a rule allowing TCP traffic on port 80 from the internet to the backend subnet.
This architecture ensures that even if an entire data center fails, your application remains online. The load balancer will detect the failure of the VMs in the affected zone and automatically reroute traffic to the healthy VMs in the other zones.
Common Questions (FAQ)
Q: Can I use an internal load balancer for private traffic?
Yes. Azure Load Balancer supports both Public and Internal configurations. An internal load balancer is ideal for multi-tier applications where you want to balance traffic between an application tier and a database tier without exposing the database tier to the internet.
Q: What happens if all my backend servers fail the health probe?
The load balancer will stop sending traffic to the backend pool. If you have no other routing mechanisms in place, the service will appear offline to the user. This is why having auto-scaling (VMSS) is so important—it can replace unhealthy instances with new, healthy ones automatically.
Q: Does Azure Load Balancer support SSL termination?
No. Layer 4 load balancers cannot see the SSL/TLS handshake. If you need SSL termination (where the load balancer handles the encryption/decryption), you must use the Application Gateway or Front Door.
Q: How many backend servers can I have?
The number of backend instances is technically very large, but you are limited by the performance of the individual instances and the total throughput of the load balancer. For most use cases, you will hit compute limits long before you hit load balancer limits.
Key Takeaways
- Layer 4 Precision: Azure Load Balancer is a high-performance, Layer 4 tool. It is protocol-agnostic and relies on five-tuple hashing to distribute traffic, making it incredibly fast for non-HTTP workloads.
- Health is Priority: The health probe is the heart of the system. Without a properly configured probe, the load balancer is blind to the state of your application. Always ensure your probe path is lightweight and accurate.
- Standard SKU is Mandatory: Always deploy the Standard SKU. It provides better security, more robust diagnostics, and is the only version that meets modern production standards.
- Plan for Outbound Traffic: Remember that Standard Load Balancers do not provide default outbound connectivity. Always account for SNAT port exhaustion and consider using a NAT Gateway for larger workloads.
- Availability Zones Matter: To achieve true high availability, deploy your backend resources across multiple zones and use a zone-redundant frontend IP for your load balancer.
- Security-First Configuration: Use Network Security Groups to restrict traffic to your backend pool. Never rely on the load balancer alone to secure your backend instances.
- Monitor the Metrics: Use Azure Monitor to keep an eye on data path availability and SNAT connection failures. Proactive monitoring is the only way to catch issues before they impact your users.
By mastering these concepts, you move beyond simply "connecting" virtual machines and into the realm of designing resilient, scalable systems that can handle the unpredictable nature of cloud traffic. Implementation is only the start; continuous monitoring and optimization are what keep your architecture performing at its best.
Reach the last section to complete this lesson and earn points — you're on section 1 of 11.
- Introduction to Azure Networking
- Introduction to Azure Networking Quiz5q
- Virtual Network Address Spaces
- Virtual Network Address Spaces Quiz5q
- Subnet Design and Configuration
- Subnet Design and Configuration Quiz5q
- Public and Private IP Addressing
- Public and Private IP Addressing Quiz5q
- Network Interface Configuration
- Network Interface Configuration Quiz5q
- Azure DNS Configuration
- Azure DNS Configuration Quiz5q
- Virtual Network Peering
- Virtual Network Peering Quiz5q
- Global VNet Peering
- Global VNet Peering Quiz5q
- Azure Virtual WAN
- Azure Virtual WAN Quiz5q
- Virtual WAN Hub Configuration
- Virtual WAN Hub Configuration Quiz5q
- Service Chaining and UDR
- Service Chaining and UDR Quiz5q
- Network Virtual Appliances
- Network Virtual Appliances Quiz5q
- Azure VPN Gateway Overview
- Azure VPN Gateway Overview Quiz5q
- Site-to-Site VPN Configuration
- Site-to-Site VPN Configuration Quiz5q
- Point-to-Site VPN Configuration
- Point-to-Site VPN Configuration Quiz5q
- VPN Gateway SKUs and Sizing
- VPN Gateway SKUs and Sizing Quiz5q
- VPN Gateway High Availability
- VPN Gateway High Availability Quiz5q
- VPN Gateway Troubleshooting
- VPN Gateway Troubleshooting Quiz5q
- ExpressRoute Overview
- ExpressRoute Overview Quiz5q
- ExpressRoute Circuit Configuration
- ExpressRoute Circuit Configuration Quiz5q
- ExpressRoute Peering Types
- ExpressRoute Peering Types Quiz5q
- ExpressRoute Global Reach
- ExpressRoute Global Reach Quiz5q
- ExpressRoute FastPath
- ExpressRoute FastPath Quiz5q
- ExpressRoute High Availability
- ExpressRoute High Availability Quiz5q
- Azure Load Balancer Overview
- Azure Load Balancer Overview Quiz5q
- Internal Load Balancer Configuration
- Internal Load Balancer Configuration Quiz5q
- Public Load Balancer Configuration
- Public Load Balancer Configuration Quiz5q
- Load Balancer Health Probes
- Load Balancer Health Probes Quiz5q
- Cross-Region Load Balancer
- Cross-Region Load Balancer Quiz5q
- Application Gateway Overview
- Application Gateway Overview Quiz5q
- Application Gateway Components
- Application Gateway Components Quiz5q
- URL Path-Based Routing
- URL Path-Based Routing Quiz5q
- Multi-Site Hosting
- Multi-Site Hosting Quiz5q
- SSL Termination and End-to-End SSL
- SSL Termination and End-to-End SSL Quiz5q
- Web Application Firewall Integration
- Web Application Firewall Integration Quiz5q
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles the points you earn on every lesson and quiz so you progress twice as fast, unlocks half of every practice exam — plus full case studies — with the Learn & Exam study modes, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× points per lesson & quiz
- ✓ 50% of every exam unlocked
- ✓ Learn & Exam modes
- ✓ Distraction-free lessons