How a load balancer works
Clients connect to one public endpoint instead of choosing a server themselves. The load balancer accepts each connection or request, selects a healthy backend and forwards the traffic.
Client → load balancer → server A
→ server B
→ server C
Health checks test backends through TCP connections or HTTP paths such as /health. A failed server is removed from selection until it recovers. Layer 4 balancers route using network and transport details such as IP addresses and ports. Layer 7 balancers can route decrypted HTTP traffic using hostnames, paths, headers or cookies.
Common balancing methods
- Round robin: sends each new request or connection to the next server in order.
- Least connections: selects the server handling the fewest active connections.
- Weighted balancing: sends more traffic to servers with greater assigned capacity.
- Hash-based routing: uses a value such as the client IP or cookie to select a consistent backend. This can provide a sticky session.
The best method depends on request duration, backend capacity and whether sessions must stay on one server.
Load balancer vs reverse proxy
| Load balancer | Reverse proxy | |
|---|---|---|
| Main job | Distribute workload | Represent backend servers |
| Backends | Usually several | One or several |
| Routing basis | Capacity, health or rules | Host, path or server rules |
The roles overlap. Many application load balancers are also reverse proxies because they receive requests on behalf of backend servers. A reverse proxy may instead focus on caching, TLS termination or filtering without balancing traffic.
How load balancing affects proxy traffic
A website’s load balancer sees the proxy server exit IP as the client network address. Requests from that IP can reach different backends unless the website uses session persistence or shared session storage.
Proxy infrastructure can also balance connections across several gateway servers. This distributes service workload, but it isn’t the same as rotating the exit IP visible to a target website.
When no backend is available, a load balancer acting as a gateway may send 503 Service Unavailable. It may send 502 Bad Gateway after receiving an invalid response from a backend.
FAQ
Is a load balancer the same as a reverse proxy?
No. Load balancing is the job of distributing traffic, while a reverse proxy is an intermediary positioned in front of servers. One system often performs both roles.
Can a load balancer prevent downtime?
It can keep a service available when one backend fails, provided other healthy backends remain and the load-balancing layer is redundant. It can’t help if every backend or a shared dependency fails.
Does a load balancer hide backend server IP addresses?
Usually, clients only need the load balancer’s public address. Backend addresses can still be exposed through DNS records, response data or configuration mistakes, so load balancing isn’t a complete security control.