Lesson 2 of 17
7. Load Balancers, Reverse Proxies and API Gateways

7.1 Why do we need a load balancer?

3 min read+10 XP

Load balancing

At the airport: Without a queue manager, three things go wrong. Some counters are swamped while others are empty. Passengers keep queueing at a counter that's broken. And you can't open or close counters without confusing everyone.

In the system: A load balancer sits between clients and a group of servers (often called a pool or target group). Every request reaches the load balancer first, and it forwards the request to one healthy server. It gives you:

  1. One address for many servers. DNS points shop.example.com at the load balancer (Chapter 4); the servers behind it can change freely.
  2. Even load. No server is swamped while others idle.
  3. Failure hiding. Dead servers are taken out of rotation automatically (7.4).
  4. Painless scaling and deploys. Add servers for the sale, remove them after, or replace them one at a time during a deploy, without users noticing (Chapter 6).

This only works if any server can handle any request, which is why servers should be stateless (Chapter 6, section 6.4).

Memory code: "One front door, many counters."