Azure Load Balancer: A Detailed and Simple Explanation

An Azure Load Balancer helps you distribute network traffic to multiple servers (or virtual machines) to balance the workload and ensure high availability of your applications. It can handle traffic coming from the internet or inside your private network.

Let’s break down the key concepts: Public and Internal Load Balancers, Load Balancing Rules, Inbound NAT Rules, and Health Probes in a simple way.


1. Public Load Balancer

A Public Load Balancer is used to distribute traffic coming from the internet. It ensures that incoming traffic is evenly distributed across multiple servers, so if one server is busy or down, the traffic will be routed to another one.

Key Features:

  • Public IP Address: The Public Load Balancer has a public IP, meaning it’s accessible over the internet.
  • High Availability: It spreads the traffic to multiple servers, so your application remains available even if one server fails.

Example:

Imagine you have a website running on 3 virtual machines (VMs). A Public Load Balancer will distribute web traffic from users on the internet evenly across those VMs, ensuring no single VM is overloaded.


2. Internal Load Balancer

An Internal Load Balancer (also known as Private Load Balancer) distributes traffic within your Azure virtual network (VNet), not from the internet. It’s used when your internal services need to balance traffic between servers inside the same network.

Key Features:

  • Private IP Address: The Internal Load Balancer has a private IP, so it’s not exposed to the internet. It’s only accessible within your Azure VNet.
  • Service Load Balancing: It’s perfect for scenarios where different internal services need to talk to each other. For example, balancing traffic between internal databases or microservices.

Example:

If your application has an internal API service running on multiple VMs, an Internal Load Balancer can distribute traffic across these VMs to make sure the load is balanced internally.


3. Load Balancing Rules

Load Balancing Rules determine how traffic is distributed among the VMs behind the load balancer. These rules define which port the load balancer listens to and how it forwards the traffic to the backend servers.

Key Features:

  • Frontend Port: This is the port that the load balancer listens to (for example, HTTP traffic on port 80).
  • Backend Port: This is the port the traffic is forwarded to on the VMs (e.g., port 80 or 443).
  • Protocol: You can set protocols like TCP or UDP for communication.
  • Distribution Mode: Load balancing rules can use different methods to distribute traffic (like round-robin or session persistence).

Example:

If your web application uses HTTP on port 80, the load balancing rule might say: "Any traffic coming to the load balancer on port 80 should be forwarded to the VMs on port 80."


4. Inbound NAT Rules

Inbound NAT (Network Address Translation) Rules allow you to map a public port on the load balancer to a specific port on a backend VM. This lets you directly connect to a specific VM behind the load balancer, even though all VMs share the same public IP.

Key Features:

  • Port Forwarding: You can forward traffic from a specific port on the load balancer to a specific port on a VM.
  • Direct VM Access: This is useful for managing individual VMs through RDP or SSH, without exposing all VMs directly to the internet.

Example:

If you have 3 VMs and want to access them individually via RDP (Remote Desktop):

  • The Inbound NAT rule could forward traffic from port 5001 on the load balancer to port 3389 (RDP port) on VM1.
  • Port 5002 on the load balancer could forward to port 3389 on VM2, and so on.

This way, each VM has its own unique port to be accessed remotely.


5. Health Probes

Health Probes check the health of the VMs behind the load balancer to make sure traffic is only sent to healthy VMs. If a VM becomes unhealthy (for example, if it crashes or becomes unresponsive), the load balancer stops sending traffic to it until it recovers.

Key Features:

  • Monitoring: Probes continuously monitor the VMs, checking their health.
  • Protocol and Port: You can configure the probe to monitor a specific port and protocol (e.g., HTTP probe on port 80 or TCP probe on port 443).
  • Unhealthy VMs Excluded: If a VM doesn’t respond correctly to the probe, it is marked as unhealthy, and the load balancer will stop routing traffic to it.

Example:

For a web app, you might configure an HTTP probe that checks if the VMs are responding to HTTP requests. If a VM doesn’t respond, the probe marks it unhealthy, and the load balancer won’t send any new traffic to that VM until it’s healthy again.


How It All Works Together: A Simple Scenario

Let’s say you have an e-commerce website hosted on 3 virtual machines (VMs) in Azure:

  1. Public Load Balancer:

    • You set up a Public Load Balancer to distribute incoming web traffic from the internet evenly across these VMs.
  2. Load Balancing Rules:

    • You create a load balancing rule that says all HTTP traffic on port 80 coming to the load balancer should be sent to the VMs on port 80.
  3. Inbound NAT Rules:

    • To manage the VMs remotely, you create inbound NAT rules, for example, using port 5001 on the load balancer to access VM1 via RDP.
  4. Health Probes:

    • You configure HTTP health probes to regularly check if the VMs are responding to HTTP requests. If any VM fails, the load balancer will stop sending traffic to it until it recovers.

This setup ensures that:

  • Your website remains available and fast because traffic is distributed across multiple VMs.
  • If one VM goes down, the load balancer directs traffic to the healthy ones.
  • You can still access each VM individually for maintenance using the inbound NAT rules.

Conclusion

An Azure Load Balancer is a powerful tool to ensure high availability and smooth traffic management for your applications. Whether you need a public load balancer for traffic from the internet or an internal load balancer for traffic inside your virtual network, you can customize it with load balancing rules, health probes, and inbound NAT rules to meet your specific needs. This makes your Azure environment scalable, secure, and easy to manage.

Comments