Video in progress

What does a load balancer do, and what happens without one?

A load balancer distributes incoming requests across several server instances and doesn't send traffic to a dead one. Without it, one server gets overloaded, or when it goes down the whole service goes down.

📖 Answer

The client knows only one address — the load balancer's. Behind it there can be 3 servers or 30, and the client doesn't notice.

A load balancer usually:

  • sends each request to one of the servers using some algorithm;
  • runs health checks and removes servers that don't respond;
  • can terminate TLS itself (TLS termination) and pass plain HTTP inside.

It works at two levels: L4 (TCP level, doesn't look inside the packet, very fast) and L7 (HTTP level, can route by URL or header). Nginx, HAProxy and AWS ALB are examples of L7.

One catch: if the load balancer itself is a single instance, it is a single point of failure too. That's why on prod they usually run in pairs, or you use the cloud provider's managed balancer.