System Design Academy

Saving…

Lesson 5 of 8 in Module 20 of 54 lessons complete

Load Balancers

Module 2, lesson 5Concept10 min

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.
  1. Look up the name

    DNS returns the load balancer’s address.

  2. Connect

    The client sends a request to that address.

  3. Choose a server

    The load balancer selects a server known to be working.

  4. 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.

One client address reaches several application servers.

Clients send requests to a load balancer, which forwards them to Server 1, Server 2 or Server 3.

FeatureLayer 4Layer 7
Visible informationAddresses and portsHTTP details after HTTPS is decrypted
Routing choiceConnection destinationRequest path such as /api/orders
Processing effortUsually less work per connectionMore work to inspect requests
ExampleUDP game trafficHTTP 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.

HTTP paths select the right server group.

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.

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

You want /api/* and /images/* on the same domain to go to different server groups. Which load balancer?
What does TLS termination at the load balancer mean?

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.

Try the quick check above whenever you feel ready.

Previous: Horizontal Scaling & Stateless Services