Azure Load Balancer

Azure Load Balancer is a Layer 4 (TCP/UDP) load balancer that enables you to distribute network traffic to your Azure virtual machines and container instances. It provides high availability and fault tolerance for your applications.

Key Features

  • High Availability: Distributes traffic across multiple instances to ensure application uptime.
  • Scalability: Handles fluctuating traffic loads by automatically scaling resources.
  • Health Probes: Monitors the health of backend instances and routes traffic only to healthy ones.
  • Layer 4 Load Balancing: Operates at the transport layer, directing traffic based on IP address and port.
  • Internal and External Load Balancing: Supports load balancing for both internal (private) and external (public) network traffic.
  • Direct Server Return (DSR): Can be configured for efficient inbound traffic flow.
  • HA Ports: Allows for load balancing of all TCP and UDP flows on all ports.

Types of Azure Load Balancers

Standard Load Balancer

Provides enhanced features such as availability zones support, a larger scale limit, and more robust diagnostic capabilities. Ideal for production workloads requiring high availability and scalability.

Basic Load Balancer

A cost-effective option for development and testing environments. It offers core load balancing functionality but lacks some advanced features of the Standard tier.

How it Works

Azure Load Balancer operates by distributing inbound traffic to a pool of backend resources, typically Virtual Machine Scale Sets or individual Virtual Machines. Health probes are configured to regularly check the responsiveness of these backend instances. If an instance fails a health probe, the Load Balancer stops sending traffic to it until it becomes healthy again.

Common Scenarios

  • Load balancing web applications across multiple web servers.
  • Distributing traffic to backend API services.
  • Ensuring high availability for critical services.
  • Improving application performance and responsiveness.

Configuration Examples

Creating a Standard Load Balancer (Azure CLI)

Create a Load Balancer:

az network lb create \
    --name myLoadBalancer \
    --resource-group myResourceGroup \
    --sku Standard \
    --frontend-ip-name myFrontendIP \
    --backend-pool-name myBackendPool

Add a health probe:

az network lb probe create \
    --lb-name myLoadBalancer \
    --resource-group myResourceGroup \
    --name myHealthProbe \
    --protocol Tcp \
    --port 80

Add a load balancing rule:

az network lb rule create \
    --lb-name myLoadBalancer \
    --resource-group myResourceGroup \
    --name myHTTPRule \
    --protocol Tcp \
    --frontend-port 80 \
    --backend-port 80 \
    --frontend-ip-name myFrontendIP \
    --backend-pool-name myBackendPool \
    --probe myHealthProbe

Resources