A single server can only handle so much. The moment you add a second one to share the load, you need something to decide which server each request goes to. That something is a load balancer, and the choices it makes shape both performance and reliability.
What a load balancer does
A load balancer sits in front of a pool of servers and distributes incoming requests among them. To clients it looks like a single endpoint; behind it, the work is spread across many machines. This delivers two things at once: more capacity, because requests are shared, and resilience, because if one server fails the balancer routes around it.
Common algorithms
- Round-robin — hand each request to the next server in turn. Simple and even when servers are equal.
- Least-connections — send each request to the server with the fewest active connections. Better when requests vary in cost.
- IP hash — route a given client consistently to the same server based on its address.
- Weighted — give more powerful servers a larger share of traffic.
Health checks
A load balancer is only as good as its awareness of its servers. Health checks periodically probe each backend, and an unhealthy server is removed from the pool until it recovers. This is what turns a load balancer from a mere splitter into a resilience mechanism: failures are detected and routed around automatically.
The sticky-session trap
Sticky sessions pin a user to one server so their session data, held in that server’s memory, stays available. It is tempting, but it undermines load balancing: traffic becomes uneven, and if that server dies, those users lose their sessions. The better pattern is to make servers stateless — store session data in a shared store like a database or cache — so any server can handle any request.
- Load balancers spread requests across servers for capacity and resilience.
- Round-robin and least-connections are the everyday algorithms.
- Health checks route around failed servers automatically.
- Prefer stateless servers over sticky sessions for even, resilient balancing.
Frequently asked questions
What is the difference between Layer 4 and Layer 7 load balancing?
Layer 4 balances on network information like IP and port without inspecting content. Layer 7 understands HTTP, so it can route based on the URL, headers or cookies — more flexible, slightly more overhead.
Does a load balancer remove single points of failure?
It removes the servers behind it as single points, but the balancer itself can become one. Production setups run balancers redundantly.