In plain English A traffic controller that shares visitors between several servers, so no single one gets overwhelmed and the site stays up if one fails.
A load balancer spreads incoming traffic across several servers, so no single one is overwhelmed and the site keeps working if one fails. Visitors connect to the load balancer’s address; it passes each request to one of the servers behind it and returns the answer.
How it chooses a server
| Method | Sends each request to |
|---|---|
| Round robin | The next server in turn |
| Least connections | The server with the fewest open connections |
| IP hash | The same server for the same visitor every time |
Health checks
A load balancer regularly requests a health check page from each server, such as /health. A server that stops answering, or returns an error, is taken out of rotation until it recovers. If every server fails its check, visitors get a 502 or 503 from the load balancer itself. A broken health check page can therefore take a working site offline.
Where you meet them
Cloud providers sell managed load balancers. Nginx and HAProxy are common self-run ones; in NginxNginx A fast, popular program that sends web pages to visitors and can pass requests on to apps behind it. More about Nginx →, servers are listed in an upstream block and requests are passed to it with proxy_pass. A load balancer is a kind of reverse proxy.
What changes for the app
Behind a load balancer, the app sees requests coming from the balancer’s address, so it must read the visitor’s real IP and protocol from the X-Forwarded-For and X-Forwarded-Proto headers. Sessions and uploaded files must be stored somewhere all servers can reach, such as a shared database or object storage, not on one server’s disk.