What is a load balancer, and what types exist?
The component that spreads incoming traffic across many servers, takes broken servers out of rotation and lets you scale horizontally. Balancing algorithms, layer 4 vs layer 7, and where load balancers sit in a real architecture.
In one sentence
A load balancer is the single entry point that receives every request and forwards it to one of many healthy servers, so no single server is overloaded and failures stay invisible to users.
What it does
- Distributes traffic across a pool of servers.
- Health checks: pings each server and stops sending traffic to the ones that fail.
- Enables horizontal scaling and zero-downtime deploys: add, remove or replace servers without users noticing.
- Often also terminates TLS, compresses responses and adds retries and rate limits.
Pick an algorithm below and take Server 2 down: notice the errors that happen until the health check detects it.
Balancing algorithms
| Algorithm | How it chooses | Best when |
|---|---|---|
| Round robin | Next server in turn | Identical servers, similar requests |
| Weighted round robin | In turn, more often for servers with more weight | Servers of different sizes |
| Least connections | Server with the fewest open requests | Request times vary a lot (uploads, reports) |
| Least response time | Fastest recent responses and fewest connections | Latency-sensitive APIs |
| IP hash / sticky sessions | Same client → same server | Sessions stored in server memory (better: make servers stateless) |
| Random with two choices | Pick two at random, send to the less busy one | Huge fleets: nearly as good as least connections, much cheaper |
Types of load balancers
The biggest distinction is how much of the request the balancer can see.
| Type | Examples | Notes |
|---|---|---|
| Layer 4 (transport) | AWS NLB, HAProxy in TCP mode | Routes by IP and port. Very fast, any protocol (TCP, UDP, WebSockets) |
| Layer 7 (application) | AWS ALB, Nginx, Envoy, Traefik | Reads HTTP: routes by path, host, header or cookie |
| DNS load balancing | Route 53, Cloudflare DNS | Returns different IPs per lookup; coarse, limited by DNS caching |
| Global (GSLB / anycast) | Cloudflare, AWS Global Accelerator | Sends each user to the nearest healthy region |
| Hardware appliance | F5 BIG-IP | Dedicated boxes in on-premise data centers |
| Client-side | gRPC client balancing, service mesh | Each client picks a server from a service registry |
Where it sits in a real system
A typical request to a large app crosses several balancers: DNS / global balancer picks a region → layer 7 balancer routes /api and /videos to different services → internal balancers spread calls between microservices and in front of database replicas.
Key takeaways
- 01A load balancer spreads requests over healthy servers and hides failures from users.
- 02Round robin is the baseline; least connections handles uneven request times; weights handle uneven servers.
- 03Layer 4 is fast and protocol-agnostic; layer 7 understands HTTP and can route by content.
- 04Balancers themselves run redundantly so they are not a single point of failure.
Check your understanding
1 of 3
What does a load balancer do?
Related concepts
Horizontal vs vertical scaling
Vertical scaling means a bigger server; horizontal scaling means more servers sharing the work. Vertical is simpler, horizontal goes further.
6 min read →Caching
A cache stores copies of data that are expensive to get (slow query, far away server) so the next request can be answered from somewhere fast and close.
9 min read →Polling
Polling means the client keeps asking the server "anything new?" on a timer. It's the simplest way to get updates, and also the most wasteful.
6 min read →API gateway
An API gateway is one entry point for all your APIs. It handles the cross-cutting work (TLS, authentication, rate limiting, routing, logging) once, so each service only does its own job.
5 min read →