Azure Load Balancer: Sharing Traffic So No Server Gets Overwhelmed
A friendly, step-by-step guide to the fast network traffic distributor that sits in front of your servers: how it chooses where to send each connection, how it detects broken servers, and how to design, secure, and monitor it well.
Imagine a large supermarket on a busy Saturday. Ten checkout counters are open, but every shopper rushes toward counter number one because it is nearest the entrance. Counter one has a huge queue, counters two to ten sit nearly empty, and the cashier at counter one is exhausted. Now imagine a friendly staff member at the entrance pointing each shopper to a counter with a short line, and quietly closing any counter whose cashier has gone on a break. Queues stay short, nobody is overworked, and shoppers hardly notice that someone is organising the flow. That staff member is a load balancer, and Azure Load Balancer is one that works at tremendous speed.
In this guide we start from the very beginning. We will learn what a server is, why a single server is risky, and how a load balancer spreads work over many servers. Then we study the parts of Azure Load Balancer, how it picks a destination for every connection, how it checks that servers are healthy, how it handles traffic leaving your network, and how to secure and monitor it. Every new word is explained when it first appears, and every big idea comes with an everyday comparison. By the end you will be able to explain the service clearly, design a sensible setup, and avoid the mistakes that catch many first-time users.
1What Is Azure Load Balancer?
Start with the one-sentence idea, then build up the picture slowly.
Azure Load Balancer is a managed Azure networking service that takes incoming network connections and spreads them across a group of servers. A server is a computer that provides a service to other computers, such as serving a website or answering database questions. In Azure, these servers are usually virtual machines, or VMs, which are software-made computers running on Microsoft’s hardware. Instead of every user connecting to one particular VM, users connect to the load balancer, which forwards each connection to one of several VMs that can do the same job.
Let us define a few words before going on. Traffic is the stream of data moving across a network. A connection is a conversation between two computers, such as a browser talking to a web server. An IP address is the number that identifies a computer or service on a network, like a street address for data. A port is a numbered door on a computer, so that one machine can offer many services at once, for example port 443 for secure web pages.
Think of a taxi rank at a railway station. Passengers do not walk around the car park looking for a particular taxi. A marshal at the front sends each passenger to the next available taxi, and waves away any taxi with engine trouble. Passengers see one entrance, while behind it many taxis share the work.
The word managed matters. You do not install load balancer software on a machine, patch it, or worry about its hardware failing. Microsoft runs it as part of the Azure network itself. You describe what you want, such as which address to listen on and which servers to use, and Azure does the rest.
Azure Load Balancer works at what is called Layer 4 of the network model. Network communication is often described in layers, from the physical cables at the bottom to the applications at the top. Layer 4 is the transport layer, where connections are made with protocols called TCP and UDP. A Layer 4 load balancer looks only at the addresses and ports on each connection. It does not read web page addresses, cookies, or the content inside the messages. That makes it extremely fast and simple, and it also defines what it can and cannot do, as we will see.
Microsoft has retired the older Basic version of the service, and the Standard version is the one to use for new work. Offerings and limits change over time, so always confirm the current options in the Azure documentation before you design.
2The Old World of One Big Server
To see why load balancing exists, look at what happens without it.
In the early days of the internet, a website often lived on one powerful server. Visitors typed the address, their requests arrived at that machine, and it answered. This was simple, cheap, and easy to understand. For a small site with a modest number of visitors, it still works fine today.
The single point of failure
The trouble with one server is that it is a single point of failure, which means one component whose breakdown stops the whole system. If the machine crashes, loses power, needs a software update, or has a bad day, the website disappears. Visitors see an error, and the business loses money and trust. Every machine fails eventually, so relying on one is a gamble.
The limit of one machine
There is also a limit on how much one machine can do. Each server has a fixed amount of processing power, memory, and network capacity. When too many visitors arrive, the server slows down and then starts refusing requests. The usual first answer is scaling up, which means buying a bigger machine. This helps for a while, but bigger machines get very expensive, and eventually the biggest one available is not enough.
Scaling up is like replacing a small bakery’s oven with the largest oven in the world. It bakes more, but if the oven breaks, the shop is closed, and it will always have a ceiling. Scaling out is like opening several ovens, so a broken one slows the shop only a little, and more ovens can be added when business grows.
Scaling out and the need for a distributor
Scaling out means adding more machines that do the same job. It solves both problems at once: if one machine fails, the others carry on, and when traffic grows, more machines are added. But scaling out creates a new question: how does a visitor know which machine to talk to? Giving each machine a different address would be a mess. The answer is one shared address held by a distributor, the load balancer, which receives all visitors and hands each of them to a suitable machine.
Maintenance without downtime
A further benefit is smooth maintenance. With several servers, an administrator can remove one from the group, update it, test it, and put it back, while the others keep serving visitors. This allows updates in the middle of the working day without a notice reading “back soon”.
3The Problems Azure Load Balancer Solves
Every service exists because somebody had a painful problem. Here are the main ones.
No single point of failure
When one server stops, the others keep answering, so users see little or no interruption.
Add servers as demand grows
New machines join the group and share the work, without changing the address users connect to.
Automatic detection of bad servers
Regular checks find servers that have stopped responding, and traffic avoids them until they recover.
Very low delay
Because it looks only at addresses and ports, it adds very little time to each connection.
Internal and public use
It can face the internet, or stay entirely inside your private network for tiers that outsiders must never reach.
Controlled outgoing traffic
It can provide the shared addresses that servers use when they connect out to the internet.
Planned and unplanned events
Servers are taken out of service for two kinds of reasons. Planned events include software updates, scaling down at night, and deploying a new version. Unplanned events include crashes, hardware faults, and network trouble. A load balancer helps with both. For planned events, an administrator removes a server from the group gracefully. For unplanned events, the health checks notice trouble automatically.
Different kinds of traffic
Not all traffic is web traffic. Databases, game servers, voice systems, remote desktops, and many custom programs use TCP or UDP on all sorts of ports. Because Azure Load Balancer works at Layer 4, it can distribute almost any of these without knowing anything about what they carry.
If your traffic is ordinary web pages and you want to route by page address or protect against web attacks, a Layer 7 service may serve you better. We compare these services in Chapter 14.
4Core Concepts You Must Know
Eight building blocks. Learn these and the rest of the topic becomes easy to follow.
Frontend IP configuration
The frontend is the address that users connect to. It is the single face the load balancer shows to the world. For a public load balancer, it is a public IP address reachable from the internet. For an internal load balancer, it is a private IP address inside your virtual network. One load balancer can have several frontend addresses.
Backend pool
The backend pool is the group of servers that receive the traffic. Members can be virtual machines, groups of VMs that scale automatically, or plain IP addresses. All members should be able to do the same job, because the load balancer treats them as interchangeable.
Health probe
A health probe is a small, regular test that the load balancer sends to each backend server to ask “are you alive and ready?”. A server that answers correctly stays in rotation. A server that fails several tests in a row is marked unhealthy, and receives no new connections until it passes again.
Load-balancing rule
A load-balancing rule ties everything together. It says, for example, “traffic arriving at this frontend address on port 443 should be shared among the servers in this backend pool, on port 443, using this health probe”. Without a rule, nothing is distributed.
Inbound NAT rule
NAT stands for network address translation, which means changing the address on a message as it passes through. An inbound NAT rule forwards traffic arriving on a certain port of the frontend to a specific single server, instead of sharing it. Administrators use these to reach one particular machine, for example for remote management.
Outbound rule
An outbound rule controls how servers in the backend pool reach the internet. It decides which public addresses they use and how many connection slots each server gets.
SKU
A SKU is the product edition, such as Standard or Gateway. The edition determines features, limits, and the promises made about reliability.
Flow
A flow is one connection identified by its source address, source port, destination address, destination port, and protocol. The load balancer makes its decisions flow by flow.
| Concept | What it is | Everyday comparison |
|---|---|---|
| Frontend IP | The address users connect to | The entrance of the taxi rank |
| Backend pool | The servers that share the work | The taxis waiting in line |
| Health probe | A regular test of each server | The marshal checking each driver is awake |
| Load-balancing rule | Maps a frontend port to the backend pool | The rule that says where passengers go |
| Inbound NAT rule | Sends a port to one chosen server | A reserved taxi for a special customer |
| Outbound rule | Controls how servers reach the internet | The station’s exit gate and badge system |
| Flow | One identified connection | One passenger’s journey |
5Architecture and Components
How the pieces fit together, from the user to the server and back.
Look at the diagram below from left to right. A user on the internet connects to the public frontend address of the load balancer. A load-balancing rule decides that this traffic belongs to a particular backend pool. The health probe tells the load balancer which servers in the pool are healthy. The load balancer then forwards the connection to one healthy server. The reply flows back to the user along the same route.
flowchart LR
U["User on the internet"] --> FE["Frontend public IP"]
FE --> RULE["Load-balancing rule"]
RULE --> BP["Backend pool"]
BP --> VM1["Server 1 - healthy"]
BP --> VM2["Server 2 - healthy"]
BP --> VM3["Server 3 - unhealthy"]
HP["Health probe"] -.->|"Checks"| VM1
HP -.->|"Checks"| VM2
HP -.->|"Checks"| VM3
A distributed service, not a single box
It is tempting to picture the load balancer as one machine sitting in the middle of the traffic. In Azure it is not. It is part of the software-defined network, spread across the data centre’s infrastructure. Because of this design, it does not become a bottleneck or a single point of failure itself, and it can handle very large numbers of connections. The packets are not rewritten by a central device that all traffic squeezes through, which is one reason it adds so little delay.
What Microsoft manages and what you manage
Microsoft manages the load balancing platform itself: its capacity, its availability, its updates, and its distribution across the network. You manage the configuration: the frontends, pools, probes, rules, and the security rules around them. You also manage the servers behind it, including their operating systems, applications, and updates. This is the shared responsibility model, and the load balancer’s high reliability does not remove your duty to build a healthy application behind it.
Where it lives in your network
A load balancer belongs to a region and works with servers inside the virtual networks of that region. A virtual network, or VNet, is your own private network inside Azure. The backend servers sit in subnets of this network, a subnet being a smaller section of the network with its own range of addresses.
A load balancer does not replace network security rules. Even if the rule and the pool are perfect, traffic still has to be permitted by the security rules attached to your servers’ network. We cover this in Chapter 12.
6How It Works Internally: Choosing a Server
What happens between “a new connection arrives” and “a server answers”.
When a new connection arrives, the load balancer must choose a backend server for it. Many people imagine a simple turn-taking scheme, where the first connection goes to server one, the second to server two, and so on. Azure Load Balancer does not work that way. Instead it uses a mathematical fingerprint of the connection, called a hash, to decide.
The five-tuple hash
A tuple is just a fixed list of values. By default the load balancer builds a hash from five values: the source address, the source port, the destination address, the destination port, and the protocol. A hash function takes these five values and turns them into a number. The number then picks one of the healthy servers. Because the source port changes with every new connection, even a single user’s different connections may land on different servers, which spreads the load nicely.
Imagine a ticket machine that reads the details on each arriving passenger’s ticket, such as the starting station, the gate, and the time, mixes them into a number, and uses the number to choose a taxi. The same ticket always gives the same number, so the same journey always goes to the same taxi, but different tickets spread across all taxis in a fair, unpredictable mix.
Why a hash and not turn-taking
Hashing has two big advantages. First, the load balancer needs to remember very little, because the same connection always produces the same answer, and this keeps it fast and scalable. Second, all packets that belong to one connection reliably go to the same server, which is essential: you cannot send half of a conversation to one server and half to another. The result over many connections is an even spread, though not a perfect one, since the distribution is statistical, like coin tosses.
flowchart TD
N["New connection arrives"] --> H["Hash source IP, source port, destination IP, destination port, protocol"]
H --> L["Look at the list of healthy servers"]
L --> C["Hash value picks one healthy server"]
C --> F["Forward the connection to that server"]
F --> M["Remember the flow so later packets follow the same path"]
Pass-through, not termination
Azure Load Balancer does not hold your connection in the middle and start a second one to the server. It is a pass-through device: the connection from the user is delivered through to the chosen server, which sees the real address of the user, and the server answers directly through the same path. This differs from services that terminate the connection and open a new one. It means the load balancer does not decrypt secure traffic, does not read page content, and does not need to hold your security certificates. Secure connections end at your servers.
Equal servers
The basic distribution treats all healthy servers as equals. It does not know that one server is busier or more powerful than another, and it does not count the active connections on each. If your servers differ widely in power, or if some requests are much heavier than others, the spread of work may be uneven. Keeping servers identical, and keeping requests reasonably similar in cost, gives the best results.
If you need smarter distribution, such as sending page requests to different servers by their web address, or reacting to server load, consider a Layer 7 service in front of or instead of the Layer 4 load balancer.
7Data Flow and Lifecycle
The life of a request, and the life of a load balancer project.
The path of one request
Follow a single visit. The user’s browser looks up the website name and receives the frontend public address. It opens a connection to that address on port 443. The packet reaches the Azure network, where the load balancer matches it to a rule, checks which servers are healthy, hashes the flow, and delivers the packet to the selected server. The server processes the request and sends the reply. The reply returns directly to the user, with the load balancer making sure it appears to come from the address the user contacted.
flowchart LR
A["Plan servers and ports"] --> B["Create virtual network and servers"]
B --> C["Create load balancer and frontend"]
C --> D["Create backend pool and health probe"]
D --> E["Create load-balancing rule"]
E --> F["Open security rules for traffic and probe"]
F --> G["Test with traffic and failure drills"]
G --> H["Operate and monitor"]
H --> I{"Servers added or removed?"}
I -->|"Yes"| D
I -->|"No"| H
Plan
Decide whether the load balancer faces the internet or stays private, which ports it serves, and how many servers you need.
Prepare the network
Create the virtual network, subnets, and the servers, spread across availability zones where possible.
Create the load balancer
Choose the Standard edition, and add a frontend address, either public or private.
Define pool and probe
Add the servers to a backend pool, and create a health probe that truly reflects readiness.
Add rules and security
Create the load-balancing rule, and allow the traffic and the probe through the network security rules.
Test and operate
Send test traffic, stop a server on purpose to watch failover, and set up monitoring and alerts.
Adding and removing servers
One of the pleasant things about a load balancer is how easy it is to change the pool. A new server is added to the backend pool, passes its health probe, and begins receiving new connections. A server being retired is removed, and new connections stop going to it. Existing connections to a server that is simply taken out of the pool may continue until they finish or reset, depending on the circumstances, so applications should be prepared to retry if a connection breaks.
Design applications so that they can reconnect. Connections do break from time to time, because of updates, failures, and idle timeouts, and a program that retries sensibly will ride through these events with hardly any visible effect.
8Health Probes and Failure Handling
The load balancer is only as smart as its idea of what “healthy” means.
Health probes are how the load balancer learns about the state of your servers. Every few seconds, it sends a small test to each server in the pool. The test can be of several kinds. A TCP probe simply tries to open a connection to a port, and if the server accepts it, the server counts as healthy. An HTTP or HTTPS probe requests a particular web address and expects a successful answer, which allows the application to say “I am ready” in its own way.
Thresholds and timing
A probe has settings for how often it runs and how many failures in a row mark a server as unhealthy. If it is too sensitive, a short hiccup removes a good server and causes needless reshuffling. If it is too relaxed, a broken server keeps receiving traffic for too long. A sensible middle ground detects real failures within a few seconds to a minute, without reacting to single blips.
What happens when a server fails
When a server fails its probes, the load balancer stops sending it new connections. The rest of the pool absorbs the traffic. When the server starts passing again, it is added back to the rotation. For connections already open on a failed server, the behaviour depends on the protocol and the circumstances. Those connections may break and need to be restarted by the client, so applications must tolerate this.
flowchart TD
P["Probe runs every few seconds"] --> R{"Server answers correctly?"}
R -->|"Yes"| H["Server stays in rotation"]
R -->|"No"| C["Count a consecutive failure"]
C --> T{"Failures reach the threshold?"}
T -->|"No"| P
T -->|"Yes"| U["Mark server unhealthy - no new connections"]
U --> Q["Keep probing the server"]
Q --> S{"Passes again?"}
S -->|"Yes"| H
S -->|"No"| Q
A health probe is like a manager who walks along the counters every few seconds asking each cashier to wave. A cashier who waves stays open. A cashier who misses several waves in a row is assumed to be away, and the sign above that counter is switched off until the cashier waves again.
Make the probe honest
A TCP probe only proves that the operating system accepts connections. The web program behind it could be crashed or stuck, and the probe would still pass. For web applications, it is better to use an HTTP probe pointing at a small, light health page that checks the things the application truly needs, such as its ability to reach its database. But keep the page cheap, because it is requested constantly by every probe from the load balancer.
The probe’s source address
Probes come from a special platform address that Azure uses for such services. Your network security rules must allow traffic from this source to your servers on the probe’s port. A very common mistake is to block it, which makes every server look unhealthy and the whole service appear broken even though the servers are fine.
If all servers in the pool fail their probes, the load balancer has nobody to send traffic to, and connections fail. Always keep the probe’s path simple, its rules open, and an alert ready for the moment the number of healthy servers drops.
9Public and Internal Load Balancers, SKUs, Zones and Cost
Choosing the right flavour and making it resilient.
Public load balancer
A public load balancer has a public IP address as its frontend. It accepts traffic from the internet and spreads it over servers that usually have only private addresses. This means the servers themselves are not directly exposed, and only the ports named in your rules can be reached through the load balancer.
Internal load balancer
An internal load balancer, sometimes called a private load balancer, has a private address from your virtual network. It is used to spread traffic between layers of an application, for example between web servers and the application servers behind them, or between your applications and a pool of database servers. It can also serve traffic that arrives from your office through a private link, such as a VPN. The outside world cannot reach it at all.
flowchart TD
I["Internet users"] --> PLB["Public load balancer"]
PLB --> W1["Web server 1"]
PLB --> W2["Web server 2"]
W1 --> ILB["Internal load balancer"]
W2 --> ILB
ILB --> A1["App server 1"]
ILB --> A2["App server 2"]
A1 --> DB["Database tier"]
A2 --> DB
Editions
The Standard edition is the main one for production. It supports availability zones, a larger pool size, richer monitoring, and a service level promise. It is also secure by default: inbound traffic is blocked until you explicitly allow it using network security rules. The older Basic edition lacked many of these features, and Microsoft has retired it, so new designs should not use it. There is also a Gateway edition, designed to place partner network appliances, such as firewalls, transparently in the path of traffic. Check the current documentation for exact capabilities.
Zones and resilience
An availability zone is a separate data centre building, or group of buildings, inside a region, with independent power, cooling, and network. A Standard load balancer frontend can be zone-redundant, meaning it survives the loss of a whole zone, or zonal, meaning it is pinned to a single zone. For most production services, zone-redundant frontends combined with backend servers spread over several zones give the strongest protection. Remember that the load balancer cannot help if all your servers are in the zone that fails.
Global load balancing
Beyond a single region, Azure offers a cross-region or global tier of load balancer. It sits in front of regional load balancers in different parts of the world and directs users to a nearby healthy region, and fails over to another region if one is lost. This is useful for global applications that use Layer 4 traffic. Details and limits change over time, so check the current documentation.
What it costs
The Standard edition is typically billed on the number of rules you configure and on the amount of data it processes, and public IP addresses and outbound data transfer carry their own charges. Internal and public load balancers differ in some respects, and prices vary by region. Use the Azure pricing calculator with your own numbers. Because rules and data volume drive the bill, avoid creating many unnecessary rules, and review them from time to time.
Cost helpers
- One load balancer can serve many ports with few rules
- No separate load balancer software or machines to run
- Shared frontends reduce the number of public addresses
- Layer 4 processing is light, with little added delay
Cost risks
- Many unused rules and forgotten test load balancers still bill
- Large data volumes through the balancer add up
- Outbound data leaving Azure is charged
- Extra public IP addresses add cost
10Inbound NAT, Outbound Connections and SNAT
Traffic leaving your network deserves as much care as traffic arriving.
Inbound NAT rules
Sometimes you want to reach one specific server rather than any server in the pool. An inbound NAT rule maps a port on the frontend to a port on one named backend server. For example, one frontend port might lead to a remote management port on server one, and another frontend port to server two. This is handy for administration, though more secure methods exist, and these ports should be tightly restricted.
The outbound problem
Your backend servers often have only private addresses, which the internet cannot route to. When such a server needs to reach the internet, for instance to download an update or call an outside service, its private address must be swapped for a public one. This swap is called SNAT, short for source network address translation. The public address is shared by many servers, so the system tells them apart using different source port numbers.
SNAT is like a company with one public telephone number and many internal extensions. When an employee calls out, the switchboard puts the company number on the call and remembers which extension it was for, so replies reach the right person. If too many employees call out at once, the switchboard runs out of free lines.
SNAT port exhaustion
Every outbound connection to the same destination address and port needs its own source port on the shared public address, and the number of ports available to each server is limited. If an application opens a great many short-lived outbound connections, such as calling an outside service for every request, it can use up its ports, and new outbound connections fail or wait. This is called SNAT port exhaustion, and it is a classic cause of mysterious, intermittent failures.
flowchart TD
S["Backend server with private IP"] --> O{"How does it reach the internet?"}
O -->|"Load balancer outbound rule"| LBO["Shared public IP with limited ports per server"]
O -->|"NAT Gateway"| NG["Dedicated public IPs with large port supply"]
O -->|"Public IP on the server itself"| PIP["Its own public IP"]
LBO --> NET["Internet"]
NG --> NET
PIP --> NET
Better ways to go outbound
For heavy or important outbound traffic, Azure recommends a NAT Gateway, a dedicated service for outbound connections that offers a large supply of ports and predictable public addresses. Another option is to give each server its own public address, though this exposes it more. Whatever you choose, check that your design deliberately addresses outbound traffic, because the default arrangements may not be enough for busy applications.
Reducing the demand for ports
Applications can also help themselves. Reusing connections instead of opening a new one for each request, using connection pooling, and keeping connections alive between requests all reduce the number of source ports needed. Microsoft’s documentation describes patterns for avoiding exhaustion, and it is wise to follow them in applications that call outside services frequently.
Watch the SNAT metrics from the start of a project. If connection counts or failures begin to climb after the application gets busy, you have found the cause before users find you.
11Session Persistence, Floating IP, HA Ports and Timeouts
Special settings for special jobs.
Session persistence
Some applications want a visitor’s connections to keep going to the same server, for example because the server remembers things about that visitor in its own memory. This is called session persistence or “sticky sessions”. With the default hash, a visitor’s separate connections may land on different servers. Azure Load Balancer can instead hash on fewer values, such as just the source address, or the source address and the protocol, so that the same client address tends to reach the same server.
Source-address persistence can spread load unevenly. If thousands of users arrive through one shared address, such as a company proxy, they all land on one server. A better design stores session data in a shared store such as a cache or database, so that any server can serve any user.
Floating IP
Some clustered applications, such as certain database availability setups, need the backend server to use the frontend address as its own. The floating IP option, known elsewhere as direct server return, lets the server accept traffic addressed to the load balancer’s frontend address and reply directly. This is a specialist setting, normally used only when the application’s own documentation requires it.
HA ports
An HA ports rule, available on internal Standard load balancers, balances traffic on all ports and protocols at once with a single rule. This is typically used for network virtual appliances, which are software firewalls or routers running on VMs, where every kind of traffic must pass through whichever appliance is healthy. It saves you from creating a separate rule for every port.
Idle timeout and keepalive
If a connection carries no data for a while, the load balancer eventually forgets it, to free resources. This period is the idle timeout, which has a default of a few minutes and can be changed within limits. If the application sends nothing during that time, and then tries to continue, the connection may be found dead. To avoid this, applications can send tiny keepalive messages that show the connection is still in use. The load balancer can also be set to send a reset to both sides when a connection times out, so that applications notice the break immediately rather than hanging.
An idle timeout is like a restaurant that gives your table to someone else if you leave it empty for too long. A keepalive is like leaving a jacket on the chair every so often to show you are still coming back.
Same-network limits
There are some special rules in how internal load balancers behave when a backend server tries to reach its own pool’s frontend address. In certain cases, the connection can fail because of how the network treats traffic that loops back to the sender. If your design needs servers in a pool to call the same frontend, check the current documentation for this limitation and for workarounds.
12Security
Who may reach what, and how to stay safe.
Security around a load balancer has several parts. What traffic is allowed in, which is filtering. Who can change the configuration, which is access control. How attacks are absorbed, which is protection against floods. And how data stays private, which is encryption.
Network security groups
A network security group, or NSG, is a set of allow and deny rules attached to a subnet or a server’s network card. The Standard load balancer is closed by default, so traffic only reaches your servers if an NSG allows it. Create rules that allow just the ports the application needs from the sources that should reach it, and allow the platform’s probe address as well. Deny everything else.
Limit exposure
Prefer internal load balancers for any tier that outsiders do not need to reach, and keep backend servers on private addresses. Avoid exposing management ports such as remote desktop or secure shell to the whole internet. Use a private path, such as a VPN or a managed bastion service, for administration.
Protection against floods
Attackers sometimes try to overwhelm a service with huge amounts of junk traffic, called a denial of service attack. Azure offers DDoS protection for public addresses, with a basic level on by default for the platform and a higher, paid level that adds tuning and support. Review the options in the documentation and choose the level that matches the risk to your business.
Encryption
Because the Layer 4 load balancer passes connections through without opening them, encryption between the user and your server is unaffected. Traffic stays encrypted all the way, and your servers hold the certificates. This is good for privacy, but it means the load balancer cannot inspect traffic for attacks or sort it by web address. For that, use a service that works at Layer 7.
Access control for administrators
Use Azure’s role-based access control, which gives each person only the permissions they need, to limit who can change or delete load balancers and their rules. A single wrong change can disconnect a whole application, so changes deserve review. Use resource locks on critical load balancers, and keep activity logs so you can see who changed what.
Security checklist
- Use the Standard edition and keep inbound closed until a rule opens it.
- Write tight NSG rules that allow only the needed ports and sources.
- Allow the probe source or the pool will look dead.
- Use internal load balancers for internal tiers, with servers on private addresses.
- Do not expose administration ports to the internet.
- Use DDoS protection at a level that fits your risk.
- Control who can change the configuration, and lock the critical resources.
- Add a Layer 7 service with a web application firewall when you need to inspect web traffic.
Because a Layer 4 load balancer does not read the content, it is not a firewall for applications. Treat it as a traffic distributor, and put real protection in the right places around it.
13Monitoring, Logging and Metrics
You cannot manage what you cannot see. Here is what to watch.
Monitoring means continuously checking the health and behaviour of your system. Metrics are numbers measured over time. Logs are written records of events. Azure Monitor collects metrics from the load balancer, and you can set alerts, which are automatic messages sent when a number crosses a line you choose.
| What to watch | Why it matters | Suggested reaction |
|---|---|---|
| Data path availability | Shows whether the frontend is answering | Alert if it falls below a high threshold, and check recent changes |
| Health probe status | Shows how many servers pass their checks | Alert when healthy servers drop below the minimum you need |
| SNAT connection count and used ports | Warns of outbound port exhaustion | Reuse connections, add a NAT Gateway, or add addresses |
| Byte and packet counts | Shows traffic volume and shape | Spot attacks, growth, and capacity needs |
| New connection counts | Shows the rate of new flows and unusual spikes | Investigate sudden jumps |
| Per-server health details | Shows which specific server is failing | Fix or replace the failing server |
Probe status is the heartbeat
The single most useful metric is the number of healthy servers. When it falls, you have lost capacity, and users may be affected soon. Set an alert that tells you when the pool drops below the number needed to carry the load, not just when it reaches zero.
Diagnostic tools
Azure provides visual views of the load balancer’s topology and health, called insights, which show the connected resources and where things have gone wrong. There are also tools to check whether traffic from one point can reach another, and logs of the rules that allowed or blocked traffic at the network security group. Together they help you answer the common question: “Is it the load balancer, the NSG, or the server?”
Troubleshooting step by step
Check probe status
If servers show unhealthy, look at the probe port, path, and whether the probe source is allowed.
Check the rule
Confirm the frontend port, backend port, and protocol match what the application listens on.
Check the security rules
Look at NSGs on the subnet and server network card, as well as any firewall inside the server’s operating system.
Check the application
Confirm the program is running and listening on the expected address and port.
Check outbound limits
For intermittent failures calling outside services, review SNAT metrics for exhaustion.
Test your failure handling on purpose. Stop one server during a quiet period and confirm that the probe notices, traffic shifts, and the application stays up. It is far better to discover a problem in a drill than in an emergency.
14Load Balancer Compared with the Alternatives
Azure offers several traffic services. Compare before you choose.
| Option | Works at | Scope | Best for | Think of it as |
|---|---|---|---|---|
| Azure Load Balancer | Layer 4, TCP and UDP | Regional, with a cross-region tier | Fast distribution of any TCP or UDP traffic, internal tiers, appliances | The marshal at the taxi rank |
| Application Gateway | Layer 7, HTTP and HTTPS | Regional | Web traffic needing path-based routing, certificates, and a web application firewall | A receptionist who reads each request |
| Azure Front Door | Layer 7, global edge | Global | Fast, protected delivery of web applications to users worldwide | A worldwide chain of reception desks |
| Traffic Manager | DNS | Global | Directing users to different endpoints through name lookups | A phone directory that points to the nearest branch |
| NAT Gateway | Outbound only | Regional | Reliable outbound connections with plenty of ports | A dedicated exit gate |
The capabilities of these services evolve, so confirm current features and limits in the documentation before you design around any of them.
A simple decision guide
flowchart TD
Q1{"Is the traffic web HTTP or HTTPS?"} -->|"Yes"| Q2{"Need routing by page address or a web firewall?"}
Q1 -->|"No"| LB["Use Azure Load Balancer"]
Q2 -->|"Yes"| Q3{"Users in many parts of the world?"}
Q2 -->|"No"| LB2["Azure Load Balancer may be enough"]
Q3 -->|"Yes"| FD["Consider Azure Front Door"]
Q3 -->|"No"| AG["Use Application Gateway"]
Layering the services
Real systems often combine them. A global service may direct users to the nearest region. Within the region, a Layer 7 gateway may inspect and route web requests. Behind it, an internal Layer 4 load balancer may spread traffic across a tier of application servers or a pool of appliances. Each service does the job it is best at, and the combination gives speed, protection, and resilience.
When Layer 4 is the right level
Choose the Layer 4 load balancer when your traffic is not web traffic, when you want the lowest delay, when you need to keep end-to-end encryption untouched, when you balance traffic inside your network between tiers, or when you need HA ports for appliances. Choose a Layer 7 service when you need decisions based on the content of web requests.
15Advantages, Disadvantages and Trade-offs
Every design choice gives something and takes something. Be honest about both sides.
Advantages
- Very fast, with little added delay
- Handles any TCP or UDP traffic, not only web
- Highly available and scalable, run as part of the Azure network
- Automatic detection and removal of unhealthy servers
- Works for both internet-facing and private tiers
- Zone-redundant options for strong resilience
- Passes encrypted traffic through untouched
Disadvantages
- No awareness of web content, so no routing by page address
- No built-in web application firewall
- Even-spread hashing ignores server load
- Outbound port limits can cause SNAT exhaustion
- Does not terminate secure connections or manage certificates
- Does not fix a poorly built application behind it
The central trade-off
The big trade-off is speed and simplicity versus intelligence. A Layer 4 load balancer is fast and simple because it knows little about your traffic. A Layer 7 service knows a lot, and can make clever decisions, but it adds processing, cost, and complexity. A good architect uses the simple tool where it is enough, and adds the clever one where it is truly needed.
Statistical fairness versus exact fairness
Hash-based distribution gives an even spread over many connections, but not an exact one. Over a short time, one server might get slightly more than another. For most workloads the difference is small, and the saving in complexity is worth it.
Stickiness versus balance
Session persistence keeps users on the same server, which helps applications that remember state, but may unbalance the load and complicates scaling. Storing state outside the servers is usually the better route, because it frees the load balancer to spread work evenly.
16Design Patterns and Anti-Patterns
Proven shapes to copy, and common shapes to avoid.
Patterns that work
Pattern 1: Zone-redundant frontend, zone-spread backend
Use a zone-redundant frontend and place servers in several availability zones. The loss of a whole zone removes only part of the capacity, and the load balancer keeps serving from the remaining zones.
Pattern 2: Public in front, internal between tiers
Expose only a public load balancer for the web tier. Use internal load balancers between the web, application, and data tiers, keeping those servers on private addresses with no direct internet exposure.
Pattern 3: Honest health pages
Give each server a small health page that checks what it truly needs, such as database access, but costs almost nothing to serve. The probe then reflects real readiness, not just that the machine is switched on.
Pattern 4: Stateless servers
Keep session data in a shared cache or database, so that any server can handle any request. Servers can then be added, removed, or replaced freely, and the load balancer can spread traffic without stickiness.
Pattern 5: Dedicated outbound path
Give busy backend servers a NAT Gateway for outbound traffic, with predictable public addresses and plenty of ports, instead of relying on defaults that can run short.
Pattern 6: Appliances with HA ports
Place a pair or more of network appliances behind an internal load balancer with a single HA ports rule, so all traffic is spread across them and survives the failure of one.
Anti-patterns
An anti-pattern is a common solution that looks sensible but causes trouble. Here are the usual ones.
What it looks like
The pool holds one server, because “we will add more later”.
Why it hurts
The load balancer adds a component but no resilience. If the server fails, the application is down, and promises about availability do not apply in practice.
Better approach
Run at least two servers, preferably in different zones, from the start.
What it looks like
A security rule denies traffic from the platform’s probe address, or the server’s own firewall refuses it.
Why it hurts
Every server appears unhealthy, and the service seems dead while the servers themselves are fine.
Better approach
Allow the probe source on the probe port in every layer of security, and test it after each change.
What it looks like
The probe requests the home page, or a page that runs a long database query.
Why it hurts
The probe adds load all day, and a slow page can cause false failures that remove healthy servers.
Better approach
Use a small, fast health page designed for the purpose.
What it looks like
The team tries to send different web addresses to different servers using only a Layer 4 load balancer.
Why it hurts
It cannot read web addresses. The team builds awkward workarounds with many ports and servers.
Better approach
Use a Layer 7 service for content-based routing, and keep the Layer 4 service for what it does best.
What it looks like
The team designs carefully for inbound traffic and never thinks about how servers reach the internet.
Why it hurts
Under load, outbound ports run out, and calls to outside services fail at random.
Better approach
Plan outbound explicitly with a NAT Gateway or controlled addresses, reuse connections, and watch the SNAT metrics.
17Best Practices and Common Mistakes
A practical list you can print and keep next to your desk.
Best practices
- Use the Standard edition for all new work, and check the current documentation for editions and limits.
- Run at least two servers, spread over availability zones, and use zone-redundant frontends.
- Keep servers identical, so that even hashing produces an even load.
- Design honest, light health probes and set sensible intervals and thresholds.
- Allow the probe source through every security layer.
- Prefer private backends. Keep servers on private addresses and use internal load balancers between tiers.
- Keep servers stateless, storing sessions in a shared store.
- Handle idle timeouts. Use keepalives and retry logic in applications, and enable resets on idle where it helps.
- Plan outbound traffic with a NAT Gateway for busy workloads.
- Monitor probe status, availability, and SNAT usage, and alert on loss of capacity.
- Test failure on purpose, including stopping a server and losing a zone in a test environment.
- Control changes. Use role-based access and locks, and review configuration changes carefully.
- Automate. Describe load balancers in an infrastructure-as-code tool, which means keeping your setup in text files so it can be repeated and reviewed.
Common mistakes
NSG blocks traffic
Creating a perfect load balancer, then forgetting the security rule that lets traffic through to the servers.
Mismatched ports
Setting a rule or probe to a port the application does not actually listen on.
Everything in one zone
Believing the setup is resilient while all servers share one data centre zone.
Unprepared applications
Programs that do not retry or reconnect, so every short interruption becomes an outage.
Expecting load-aware routing
Assuming the load balancer sends traffic to the least busy server, when it only hashes flows.
Ignoring the hairpin case
Having a backend server call its own pool’s internal frontend and meeting a connection failure.
18Real-World Scenarios
Four typical situations, described as illustrative examples, showing when the service fits.
The stories below are illustrative composites of the kinds of situations where teams commonly use Azure Load Balancer. They are not claims about any particular company, but they reflect the reasoning real architects use.
Scenario 1: A web shop with a three-tier design
An online shop runs web servers, application servers, and a database cluster. A public load balancer with a zone-redundant frontend spreads secure web traffic across web servers in three zones. An internal load balancer sits between the web and application tiers, keeping the application servers private. A small health page on each server checks database access. During a planned update, the team removes one server at a time from the pool, and shoppers notice nothing.
Scenario 2: A game server fleet using UDP
A studio runs real-time game servers that talk over UDP. Since the traffic is not web traffic, a Layer 4 load balancer is a natural fit, and its low added delay matters to players. Servers are identical, and the team tests that health probes on a separate port detect a frozen game process quickly. For outbound calls to a login service, the team adds a NAT Gateway after seeing intermittent failures from port exhaustion during a launch week.
Scenario 3: A firewall pair for a company network
A company runs two virtual firewall appliances from a partner and wants all traffic between its network zones to pass through whichever one is healthy. An internal load balancer with an HA ports rule distributes every kind of traffic across both appliances, and a probe checks each appliance’s management port. When one appliance is rebooted for an update, traffic continues through the other, and security staff avoid a late-night maintenance window.
Scenario 4: A clustered database and its shared address
A team runs a clustered database in which only one node is the active primary at a time. An internal load balancer with a probe that succeeds only on the primary sends all connections to the right node, and a floating IP setting follows the database vendor’s guidance. When the cluster fails over, the probe on the new primary starts passing, the old one stops, and applications reconnect to the same address, with only a brief pause.
In all four scenarios the team used honest health probes, spread servers over zones, planned outbound traffic, and tested failure on purpose. Those habits matter more than any single setting.
19Frequently Asked Questions
Short answers to the questions beginners ask most often.
20Summary and Key Takeaways
Everything important, in one place.
Azure Load Balancer is a fast, managed Layer 4 service that spreads TCP and UDP connections across a pool of healthy servers behind one shared address. It uses a hash of each connection’s details to choose a server, checks the health of every server with regular probes, and avoids those that fail. It can face the internet or stay private, can survive the loss of a zone when designed that way, and can also manage how servers reach the internet. It does not read web content, does not decrypt traffic, and does not fix a poorly built application behind it.
Remember the comparison we began with: a staff member at the supermarket entrance pointing shoppers to counters with short lines and closing counters whose cashiers have gone. That helper is valuable only if there are enough counters, if each is staffed by a capable cashier, and if the signs honestly show which ones are open. Treat Azure Load Balancer the same way: run several identical servers, give them honest health checks, plan how traffic leaves as well as how it arrives, and test what happens when something breaks.
Key Takeaways
- What it is: a managed Layer 4 load balancer that spreads TCP and UDP connections across healthy servers.
- Parts to remember: frontend address, backend pool, health probe, load-balancing rule, inbound NAT rules, and outbound rules.
- How it chooses: a hash of the connection details gives a statistically even spread, with all packets of a flow reaching the same server.
- Health is everything: use honest, light probes, allow the probe source through every security layer, and alert on lost capacity.
- Design for resilience: use the Standard edition, zone-redundant frontends, servers in several zones, and stateless applications.
- Plan outbound traffic: avoid SNAT port exhaustion with a NAT Gateway and connection reuse.
- Pick the right tool: use Layer 4 for speed and any protocol, and add a Layer 7 service when you need web routing, certificates, or a firewall.