Introduction
Think of the last time a big website went down in the middle of something important. A ticket sale opens, a new phone goes on pre-order, a football final kicks off, and suddenly the site will not load. The page spins, the button does nothing, and thousands of people are staring at an error message at exactly the moment they most wanted to get in.
Most people blame the website, but the company probably had plenty of computers. The problem was that all the visitors arrived at the same one, while the others sat idle. It is like a shop with ten tills open and a queue a mile long at the first one, because nobody told the customers the other nine existed.
Load balancing is the job of telling the customers about the other nine tills. It is the quiet piece of machinery that stands in front of a website and shares the visitors out across many servers, so no single machine gets crushed while the rest stand around doing nothing.
This article explains how it works, in plain language: what a load balancer actually does, the main ways it shares out traffic, how it copes when a server dies, and what happens when the balancer itself is the thing that breaks.
The Problem: One Server, Too Many Visitors
Every website runs on a server, which is just a computer that answers requests. When you visit a page, your browser sends a request, the server does some work — looking up data, building the page — and sends the answer back. A single server can do this hundreds or thousands of times a second — until too many people arrive at once.
The trouble starts when a site becomes popular, or when popularity arrives all at once. A small online shop might hum along happily with one server for years, serving a few dozen visitors at a time. Then a video about it goes viral, or a newspaper mentions it, or it runs a sale, and suddenly ten thousand people arrive in the same hour. And sometimes the flood is not real visitors at all — a DDoS attack can drown a site in fake traffic the same way. The server tries to answer them all, and it cannot. Requests pile up, answers slow down, and eventually the server stops answering at all.
The obvious fix is to add more servers. Buy a second computer, then a third, and share the work between them. That works, but it creates a new problem: how does a visitor know which server to talk to? A website address points to one place. When you type in an address, your browser expects one answer. If there are five servers behind that address, something has to decide which one gets your request. Without that something, adding servers does nothing — every visitor still arrives at the first one, and the other four sit idle, waiting for work that never comes.
That missing piece is the load balancer, which takes the address the world sees and quietly distributes the visitors behind it.
When It Goes Wrong: Three Real Crashes
This is not a theoretical problem. Some of the biggest websites on earth have fallen over in exactly this way, and the numbers are public.
In November 2022, Ticketmaster opened the presale for Taylor Swift's Eras Tour. About 3.5 million fans had pre-registered, and 1.5 million of them were given codes to buy. On the day, 14 million people turned up, bots included, according to Live Nation's chairman — and Ticketmaster said its systems received 3.5 billion requests, four times its previous peak. The site crashed within the hour. Queues froze, tickets vanished from people's carts, and the planned public sale was cancelled two days later. In the end 2.4 million tickets were still sold that day, a record, but the mess ended up in front of a US Senate hearing.
In July 2018, Amazon's Prime Day sale opened at 3pm and the site crashed within minutes. The problems lasted about 75 minutes, and analysts estimated the outage cost Amazon around $1.2 million a minute in lost sales — roughly $90 million in total. Internal documents later showed that one of Amazon's own systems had handled 63.5 million requests a second during the previous year's sale. Even Amazon, with all its machinery, could be brought down by a crowd arriving faster than the front door could cope with.
And in October 2013, the US government's HealthCare.gov launched with 250,000 people arriving at once — five times the number the site was built to expect. It started failing within two hours. On the first day, only six people managed to enrol. By the second morning the total was 248. The site took two months to recover.
None of these were small websites, and none of them were short of computers. The failure in each case was the same: too many visitors arriving at once, and no good way of sharing them out. That is the problem load balancing exists to solve.
What a Load Balancer Actually Does
A load balancer sits between the visitors and the servers. Every request from the outside world arrives at the balancer first. The balancer picks one of the servers behind it, passes the request along, waits for the answer, and hands it back to the visitor. The visitor never knows any of this happened. As far as they can tell, they talked to the website, and the website answered.
The balancer has to make that decision in a fraction of a second, thousands of times a second, without becoming the bottleneck itself. It also has to be fair. If it sends every request to the fastest server, that server will slow down and the fast one will become the slow one. If it ignores a server that is struggling, that server will keep getting work it cannot handle. The art of load balancing is not just sharing the work out — it is sharing it out in a way that keeps every server roughly as busy as every other one.
There are two broad kinds of load balancer. The first is software: a program running on an ordinary server, doing nothing but directing traffic. This is what most websites use today, because it is cheap, flexible, and easy to change. The second is hardware: a dedicated box, built for one job, that sits in a data centre and directs traffic at enormous speed. Big companies and banks still use these, because when you are handling millions of requests a second, a specialised machine earns its keep.
The balancer also watches the servers: if one stops answering, it stops sending it visitors.
Round Robin and the Other Ways to Share the Load
The simplest way to share out visitors is called round robin, and it is exactly what it sounds like. The first visitor goes to server one, the second to server two, the third to server three, and then it starts again at server one. It is fair and simple, and it works well as long as all the servers are roughly equal and the requests take roughly the same effort.
But real life is rarely that tidy. Some requests are light, like loading a small image. Others are heavy, like searching a database or generating a report. If the balancer hands out requests blindly, one server can end up with all the heavy ones by bad luck. So balancers have smarter methods.
One common method is called least connections. Instead of going in order, the balancer sends each new visitor to the server that currently has the fewest active visitors. A server that is busy with slow, heavy requests gets a rest, while a server that is sitting idle gets the next arrival. This adjusts itself naturally as the load changes, and it handles the case where some servers are faster than others: a fast server finishes its work sooner, so it has fewer active connections, so it gets more visitors. The system balances itself.
Another method is based on the visitor's address. The balancer looks at the visitor's internet address and uses it to pick a server — the same visitor always goes to the same server. This is called IP hashing, and it is useful when a website needs a visitor to keep talking to the same machine. We will come back to why that matters in a moment.
There is no single best method: small sites use round robin, busy sites use least connections, and sites with special needs use hashing. In short:
- Round robin — visitors are shared out in turn, one after another. Simple and fair when the servers are equal.
- Least connections — each new visitor goes to the server with the fewest people on it right now. It adjusts itself as the load changes.
- IP hash — the visitor's address decides the server, so the same visitor always lands on the same machine. Useful when a visitor needs to stay put.
Health Checks: Noticing When a Server Goes Down
Sharing out the visitors is only half the job. The other half is noticing when a server stops working, and doing something about it before the visitors do.
Servers fail all the time, for reasons that are usually boring. A hard drive fills up. A program crashes. A power supply dies. A piece of software is updated and the update has a bug in it. The problem is that a failing server does not put up its hand and say so. It just stops answering, or starts answering very slowly, or answers with errors. If the balancer keeps sending it visitors, those visitors get nothing.
So the balancer checks on the servers constantly. Every few seconds, it sends each server a small test request — something simple, like asking for the homepage, or asking a special health page that answers "I am fine" when everything is working. If the server answers quickly, it stays in the rotation. If it does not answer, or answers with an error, the balancer quietly takes it out of the list. Visitors are sent to the servers that are still healthy, and nobody notices that one machine has gone dark.
This is called a health check, and it is what makes load balancing genuinely useful rather than just a clever trick. Without health checks, adding more servers would make a site less reliable, not more: every extra server would be another chance for a visitor to land on a broken one. With health checks, every extra server is another spare. A site with five servers can lose one and carry on. A site with one server cannot lose anything at all.
The checks work in reverse, too: when a fixed server starts answering again, the balancer puts it back in the rotation by itself.
Sticky Sessions: When a Visitor Needs to Stay Put
Most of the time, it does not matter which server answers a visitor. Any of them can show the homepage, any of them can serve a product page, any of them can handle a search. But sometimes it does matter, and the reason is usually a shopping basket.
Imagine you are buying something online. You add a pair of shoes to your basket on server one. Then you click to the checkout page, and the balancer sends you to server two. Server two has never met you. It has no idea about your basket. It shows you an empty cart, and you stare at the screen wondering where your shoes went.
This is the session problem, and the fix is called a sticky session. When a visitor first arrives, the balancer picks a server for them — and then sticks them to it. Every request from that visitor goes to the same server for the rest of their visit. The basket stays put. The login stays put. The half-filled form stays put.
Sticky sessions work, but they have a cost. If one server ends up with all the sticky visitors who happen to be shopping at the same time, it gets overloaded while the others sit idle. The balancer's careful sharing is partly undone. And if the server a visitor is stuck to dies, the visitor loses their basket anyway — the balancer can move them to a healthy server, but the new server does not have their basket either.
That is why many modern websites store the basket in a shared database all servers can reach, so it does not matter which server answers. Sticky sessions are still used, but the best fix is to design the problem away.
What Happens When the Balancer Itself Fails
There is an awkward question hiding in all of this. If the load balancer stands in front of every server, and every visitor goes through it, then what happens when the balancer breaks? The answer is uncomfortable: everything stops. One balancer is a single point of failure, and a single point of failure is exactly what load balancing was supposed to remove.
The fix is to have more than one balancer, which sounds like a joke — balancers to balance the balancers — but it is how real systems work. Usually there are two balancers, one active and one standing by, watching the first one. They share a single address, and if the active one stops answering, the standby takes over within seconds. Visitors never notice; the engineers get an alert and fix the broken one at their leisure.
For very large sites, this goes further. There are layers of balancers: one at the edge of the network, sending visitors to different data centres; one inside each data centre, sending visitors to different groups of servers; and sometimes one more, inside the application itself, sharing work between smaller services. Each layer is redundant, each layer watches the layer below it, and the failure of any single piece becomes a non-event.
The deeper lesson: reliability does not come from machines that never fail — every machine fails eventually. It comes from a system in which any single machine can fail without the whole thing falling down.
Load Balancing Beyond the Website
So far we have talked about websites, because that is the easiest place to see load balancing at work. But the same idea shows up everywhere in modern software, in places you would never notice.
Databases use it. A busy application might have one database that takes all the writes — new orders, new accounts, new messages — and several copies that handle the reads. When the application needs to look something up, a balancer sends the question to whichever copy is least busy. The copies stay in sync behind the scenes, and the application does not care which one answered.
Email uses it too: a balancer decides which mail server handles your message, and if one is down for maintenance, the others take the load.
Even the apps on your phone use it, though the balancing happens far away, in the cloud. When you open a video app, your request travels to the nearest data centre, where a balancer sends it to one of hundreds of servers that all hold the same videos. Live features that stay connected in real time, like chat and notifications, need the same treatment — that is what WebSockets are for. If you open the app again an hour later, you will probably reach a different server, and you will never know. The experience feels instant and effortless, and the reason it feels that way is that somewhere, quietly, a balancer is doing its job.
The pattern is always the same: a job too big for one machine, a group of machines to share it, and a balancer in front deciding who does what. Once you see it, you see it everywhere.
When a Small Site Actually Needs One
After all of this, you might be wondering whether your own website needs a load balancer. For most small sites, the honest answer is no — not yet.
A load balancer earns its keep when one server is not enough. If your site gets a few hundred visitors a day, one server handles that easily, and adding a balancer would just add a piece of machinery to maintain, another thing that can break, and another bill to pay. A single well-run server, with good backups, will serve a small business well for years.
The moment to think about it is when the signs start showing:
- Pages load slowly at busy times.
- The server struggles during a sale or an event.
- You find yourself worrying about what happens if the server goes down on a Saturday, when nobody is around to fix it.
- You want to update the site without taking it offline, which a balancer makes possible: you take one server out, update it, put it back, and do the same to the next, while visitors keep using the ones that are still running. Good deployment pipelines do this routinely.
When that moment comes, you probably do not need to build one yourself: the cloud companies all offer load balancing as a service. You point it at your servers, and they worry about the standby balancer, the health checks, and the failover.
Conclusion
Load balancing is one of those ideas that sounds complicated and turns out to be simple at heart. A website has more visitors than one computer can handle. So it uses several computers, and it puts something in front of them to share the visitors out. That something checks that the computers are healthy, sends visitors to the ones that are least busy, and steps aside when a computer breaks. And because the balancer itself could break, there are two of them, so the system survives that too.
The result is the experience we all take for granted: websites that stay up when millions of people arrive at once, that keep working when a server dies in the middle of the night, that can be updated without ever going offline. None of that happens by accident. It happens because someone built a system in which no single failure matters.
You will probably never set one up yourself. But the next time a big site stays up through a rush that should have flattened it, you will know what is standing between the crowd and the crash.
Frequently Asked Questions
What is the difference between load balancing and a CDN? They solve different problems, though they often work together. A CDN, or content delivery network, stores copies of your site's files — images, videos, pages — on servers all over the world, so a visitor in Sydney gets files from Sydney instead of from a server in London. A load balancer shares live traffic across your own servers, deciding which one answers each request. A CDN makes things faster by being close to the visitor; a load balancer makes things reliable by spreading the work.
Can a load balancer make my website faster? It can, but that is not really its job. If your site is slow because one server is overloaded, adding servers and a balancer will help, because the work gets shared out. But if your site is slow because the pages are heavy, the database is slow, or the code is doing too much work on every request, a balancer will not fix any of that — it will just spread the slowness across more machines. Fix the slow parts first. Serving cached copies of the heavy pages often helps more than extra servers.
What happens to my shopping basket if a server dies? It depends on how the site is built. If the basket is stored on the server itself, and that server dies, the basket is gone, and you will have to start again. That is why well-built sites store baskets in a shared database that every server can reach. Then it does not matter which server answers you, because they all look up the same basket.
Do I need a load balancer for a small website? Almost certainly not. A small site with a few hundred visitors a day runs happily on one server, and a balancer would just be another thing to maintain and pay for. Think about it when the signs show up: slow pages at busy times, worry about what happens if the server goes down, or wanting to update the site without taking it offline. When that day comes, the cloud providers all offer load balancing as a service, so you can switch it on w
Comments
Post a Comment