How load balancers keep sites online

A load balancer sits between users and servers, spreading traffic so no single machine is overloaded and one failure does not take a site down.

Key takeaways

  1. One server hit by thousands of users at once can slow down or crash.

  2. A load balancer sits between users and servers and spreads the traffic.

  3. If one server gets too busy, requests go to another.

  4. If a server goes down, the others keep working, so uptime improves.

What happens when thousands of users hit the same server at once? It gets overwhelmed: it slows down, or it crashes completely. The fix is not always a bigger server. Often it is more servers, with something in front of them deciding which one handles each request. That something is a load balancer.

How it works

Instead of sending everything to one machine, a load balancer sits between your users and your servers. Incoming requests reach the load balancer first, and it spreads that traffic across multiple servers, so no single machine gets overloaded. To users, it still looks like one website at one address.

Load balancers use simple rules to pick a server. Two common ones:

  • Round robin: send each new request to the next server in the list, in turn.
  • Least connections: send it to the server handling the fewest connections right now.

When a server struggles or fails

If one server gets too busy, requests go somewhere else. If one goes down, the others keep working. To know which servers are healthy, load balancers run health checks: they regularly test each server, stop sending traffic to any that fail to respond, and bring them back once they recover.

More traffic. Less overload. Better uptime.

Why it matters

Most large websites and apps rely on load balancing. It is what lets a service handle a rush of visitors by adding servers behind the balancer, and what lets engineers update or replace one server at a time without taking the whole site offline. When a server fails and you never notice, a load balancer is often the reason.

All explainers

Loading related explainers