7. Load Balancers, Reverse Proxies and API Gateways
1
The picture to keep in your head2
7.1 Why do we need a load balancer?3
7.2 What's the difference between a layer 4 and a layer 7 load balancer?4
7.3 How does the load balancer choose a server?5
7.4 How does the load balancer know a server is dead?6
7.5 What are sticky sessions, and should you use them?7
7.6 What is SSL termination?8
7.7 If everything goes through the load balancer, what if it fails?9
7.8 What's the difference between a forward proxy and a reverse proxy?10
7.9 What is an API gateway?11
7.10 How do you balance traffic across regions?12
Memory card and where the analogy breaks13
Practice: five levels14
Interview questions15
Solutions16
Sources17
Code lab7. Load Balancers, Reverse Proxies and API Gateways
Memory card and where the analogy breaks
3 min read+10 XP
The memory card (tear this page out)
| # | Question | Memory code |
|---|---|---|
| 7.1 | Why a load balancer? | One front door, many counters |
| 7.2 | L4 vs L7? | L4 reads the envelope, L7 reads the letter |
| 7.3 | Algorithms? | Take turns, weigh the big ones, pick the shortest queue, or keep families together |
| 7.4 | Health checks? | Three misses and the sign goes up; two passes and it comes down |
| 7.5 | Sticky sessions? | Sticky sessions hide state; they don't remove it |
| 7.6 | SSL termination? | Open the envelope once, at the gate |
| 7.7 | Redundant load balancer? | Every front door needs a spare door |
| 7.8 | Forward vs reverse proxy? | Forward proxy speaks for the clients; reverse proxy speaks for the servers |
| 7.9 | API gateway? | Check ID once at the gate, not at every counter |
| 7.10 | Global load balancing? | Pick the airport first, then the counter |
The whole chapter in one line: One front door with a spare, a smart rule for picking counters, and closed signs on the broken ones.
Where the analogy breaks
- A queue manager handles a few hundred passengers an hour. A load balancer handles thousands of requests a second, so its own speed and redundancy matter enormously.
- Passengers can see the queues. Requests can't, so the load balancer has to estimate how busy each server is from connection counts and response times.
- A broken counter is obvious. A sick server isn't: it may answer health checks while failing real requests, or fail checks while serving fine. Health checks are a guess, not the truth.
Quick check
Five questions on this chapter. Pick an answer, then check it.
quiz