# Load balancer

> The traffic cop that spreads incoming requests across many servers.

- Level: Intermediate
- Topics: Networks, Cloud
- URL: https://tidbit.legios.com.ar/load-balancer/
- In Spanish: [Balanceador de carga](https://tidbit.legios.com.ar/es/load-balancer/)

A **load balancer** sits in front of a group of servers and distributes incoming requests among them. Users all connect to one address (the balancer's); behind it, the same website or API runs on two, ten or a thousand identical machines, and each request is sent to one of them. The user never knows which.

It solves two problems at once. **Capacity**: one server can only handle so many requests per second, so you add more and split the load. **Availability**: the balancer checks each server's health every few seconds and stops sending traffic to one that fails, so a crashed machine means a slightly busier fleet instead of an outage. It also lets you update servers one at a time with no downtime.

Balancers choose servers with simple rules (round robin, fewest connections, by region) and many also terminate HTTPS, so the TLS certificate lives in one place. In the cloud this is a managed service: AWS has the Application Load Balancer and the Network Load Balancer, and platforms like Kubernetes build one in. Combined with autoscaling (add servers when busy, remove them when quiet), a load balancer is what lets a site survive being on the news.

## An analogy

The person at the bank entrance who sends each customer to the next free window. Ten windows, one queue; if a teller goes on break, nobody is sent there.

## Keep in mind

- One public address in front, many identical servers behind.
- Health checks pull a broken server out of rotation automatically.
- It is what makes zero-downtime deploys and autoscaling possible.
- Often also terminates HTTPS, so certificates live in one place.

## Go deeper

- [What is load balancing? (Cloudflare)](https://www.cloudflare.com/learning/performance/what-is-load-balancing/)
- [Load balancing, computing (Wikipedia)](https://en.wikipedia.org/wiki/Load_balancing_(computing))

## Related terms

- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
- [API](https://tidbit.legios.com.ar/api/): The menu of things one program lets another program ask for.
- [Regions and Availability Zones](https://tidbit.legios.com.ar/regions-and-availability-zones/): Where AWS physically lives: cities worldwide, each split into separate data centers.
- [HTTPS](https://tidbit.legios.com.ar/https/): The padlock in your browser: web traffic nobody in between can read.
- [TLS certificate](https://tidbit.legios.com.ar/tls-certificate/): The ID card a website shows your browser to prove it is who it claims to be.
- [Cloud computing](https://tidbit.legios.com.ar/cloud-computing/): Renting computers over the internet instead of buying your own.
- [Kubernetes](https://tidbit.legios.com.ar/kubernetes/): The system that runs and babysits containers across many machines.
- [Autoscaling](https://tidbit.legios.com.ar/autoscaling/): Adding and removing servers automatically as demand goes up and down.
