System Design Playbook
14 · Performance & traffic8 min read

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.

Load balancer algorithms
Algorithm
12345ClientLoad balancerRound robin● Server 10 active · 0 handled● Server 20 active · 0 handled● Server 3 · 2× capacity0 active · 0 handled● Server 40 active · 0 handled
Requests
0
Busiest server
0 active
Failed requests
0
Health check
all healthy
Round robin hands requests out in turn. Simple and fair when servers and requests are similar, but it ignores that S3 is bigger and that some requests take longer.
Each colour is a different client. Bars under each server show its open connections.

Balancing algorithms

AlgorithmHow it choosesBest when
Round robinNext server in turnIdentical servers, similar requests
Weighted round robinIn turn, more often for servers with more weightServers of different sizes
Least connectionsServer with the fewest open requestsRequest times vary a lot (uploads, reports)
Least response timeFastest recent responses and fewest connectionsLatency-sensitive APIs
IP hash / sticky sessionsSame client → same serverSessions stored in server memory (better: make servers stateless)
Random with two choicesPick two at random, send to the less busy oneHuge 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.

Layer 4 vs layer 7 load balancing
Balancer type
HTTP requestURL path /api/videosHeaders & cookiesMethod, host, bodyL7 · ALB / NginxRoutes by: path/api/*API servers/videos/*Video serversThe content: /api → API servers, /videos → streaming servers, A/B by cookie.
Layer 4 balancers (like AWS NLB) forward connections without opening them: very fast. Layer 7 balancers (like AWS ALB, Nginx, Envoy) terminate HTTP, so they can route by path or header, add TLS and retries.
TypeExamplesNotes
Layer 4 (transport)AWS NLB, HAProxy in TCP modeRoutes by IP and port. Very fast, any protocol (TCP, UDP, WebSockets)
Layer 7 (application)AWS ALB, Nginx, Envoy, TraefikReads HTTP: routes by path, host, header or cookie
DNS load balancingRoute 53, Cloudflare DNSReturns different IPs per lookup; coarse, limited by DNS caching
Global (GSLB / anycast)Cloudflare, AWS Global AcceleratorSends each user to the nearest healthy region
Hardware applianceF5 BIG-IPDedicated boxes in on-premise data centers
Client-sidegRPC client balancing, service meshEach 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