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.8 What's the difference between a forward proxy and a reverse proxy?
3 min read+10 XP
Beyond load balancing
At the airport: A travel agent books flights on behalf of passengers: the airline sees the agent, not you. An airline's head office answers all customer calls on behalf of its many departments: you talk to one number, not to each department.
In the system: A proxy is a middleman that forwards requests. The difference is whose side it's on.
- A forward proxy sits in front of clients. Office laptops send all web traffic through it; it can filter sites, cache, log, and hide the clients' addresses. Websites see the proxy, not the individual user.
- A reverse proxy sits in front of servers. Clients talk to it as if it were the server; it forwards to the real servers behind. It can load-balance, terminate TLS, cache responses, compress, and hide the servers' addresses.
A load balancer is a reverse proxy whose main job is spreading load. Tools like NGINX, HAProxy and Envoy can play any of these roles depending on how they're configured.
Memory code: "Forward proxy speaks for the clients; reverse proxy speaks for the servers."