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
7.10 How do you balance traffic across regions?
3 min read+10 XP
At the airport: A traveller in Mumbai and one in London both want "the airline". Each is sent to the nearest airport first; inside each airport, the queue manager takes over.
In the system: Global load balancing picks a region (or data centre) first; regular load balancers then pick a server inside it. Two common ways:
- DNS-based (GeoDNS): the DNS answer depends on where the user is, and health checks remove a dead region (Chapter 4, section 4.6). Simple, but slowed by DNS caching.
- Anycast: the same IP address is announced from many locations, and the internet's routing delivers each user to the nearest one. Large CDNs and some cloud global load balancers work this way (Chapter 26).
The hard part isn't routing; it's data. Sending a user to a second region only helps if that region has their data, which brings in replication and consistency (Chapters 14 and 16).
Memory code: "Pick the airport first, then the counter."