Load Balancers
Definition
Load balancer
- In plain English
- A load balancer receives incoming requests and spreads them across several servers.
- Think of it like
- It is like a restaurant host who seats each new group at a table with room.
UDP
- In plain English
- UDP sends separate network messages without establishing a connection or guaranteeing their delivery.
- Think of it like
- It is like sending postcards without a delivery receipt.
Why it exists
You have three servers, but users need one address. Asking each phone to track healthy servers makes every client harder to maintain.
A load balancer gives clients a stable destination. Behind it, you replace servers and change their number.
How it works
Layer 4 and layer 7
- In plain English
- A layer 4 load balancer routes using only addresses and ports, while a layer 7 load balancer can read the HTTP request, such as its path.
- Think of it like
- Like a mail sorter who reads only the postcode versus one who opens the envelope to find the department.
TLS termination
- In plain English
- TLS termination means the load balancer decrypts HTTPS so the servers behind it receive plain requests.
- Think of it like
- Like a front desk that signs for parcels and unpacks them before passing them on.
- Look up the name
DNS returns the load balancer’s address.
- Connect
The client sends a request to that address.
- Choose a server
The load balancer selects a server known to be working.
- Forward and reply
It forwards traffic, and the response returns through it.
Clients send requests to a load balancer, which forwards them to Server 1, Server 2 or Server 3.
| Feature | Layer 4 | Layer 7 |
|---|---|---|
| Visible information | Addresses and ports | HTTP details after HTTPS is decrypted |
| Routing choice | Connection destination | Request path such as /api/orders |
| Processing effort | Usually less work per connection | More work to inspect requests |
| Example | UDP game traffic | HTTP paths routed to different services |
Examples
Route by request path
The clinic uses one domain for appointments and pet images. A layer 7 load balancer reads each request path.
Paths beginning /api/ go to application servers. Paths beginning /images/ go to image servers.
The clinic app contacts one layer 7 balancer. API paths reach API servers, while image paths reach image servers.
The insight
Layer 7 lets one address serve several kinds of request.
Route game connections
In-match game traffic uses UDP rather than HTTP. UDP sends messages without TCP’s connection and delivery guarantees.
Choose a layer 4 balancer that supports UDP. Keep each player’s match traffic assigned to the correct game server.
- HTTP path rules do not apply to these messages.
- Distribute new traffic without moving players between live matches.
The insight
Choose a balancer that supports your traffic’s protocol.
Protect both connections
The pharmacy installs its public certificate at the load balancer. Medical refill requests also need encryption inside the private network.
The balancer decrypts the incoming HTTPS request. It then opens a new TLS-protected connection and verifies the destination server.
The phone uses HTTPS to the load balancer. After decrypting there, the balancer sends the refill request over a new HTTPS connection to the servers.
The insight
Centralising public certificates does not remove the need to protect internal traffic.
Trade-offs
Pros
- Give clients one stable address.
- Spread work across healthy copies.
- Centralise public certificates.
Cons
- Add a small forwarding delay.
- Run another component.
- Protect it against overload and failure.
Use when
- Route traffic among several servers.
- Use HTTP paths to select services.
Avoid when
- Avoid an unnecessary extra layer for one small server.
- Avoid a lone balancer when outages are costly.
Quick check
Takeaways
- A load balancer provides one front door to many servers.
- Layer 4 routes by addresses and ports; layer 7 understands HTTP.
- Protect the load balancer itself against failure.