Load balancer vs API gateway
Both sit at the front door, but one spreads traffic across identical servers while the other manages and routes API calls across many services.
Both front your system — different jobs
A load balancer and an API gateway both receive incoming traffic, so people conflate them. The distinction: a load balancer’s job is distribution; an API gateway’s job is API management and routing.
Load balancer
Spreads requests across a pool of interchangeable servers to balance load and remove single points of failure. It mostly doesn’t care what the request is — it cares which healthy server should handle it. (Full treatment in Chapter 2.)
- Operates at: L4 (IP/port) or L7 (HTTP).
- Knows about: server health and load.
- Core value: scalability and availability of one service.
API gateway
A single entry point in front of many different services (especially in a microservices architecture) that handles cross-cutting API concerns so each service doesn’t have to:
-
Routing — send
/users/*to the user service,/orders/*to the order service. -
Auth — authenticate and authorize once, centrally.
-
Rate limiting & throttling — protect backends from abuse.
-
Aggregation — fan one client request out to several services and combine responses.
-
Cross-cutting glue — TLS termination, request/response transformation, logging, caching, API versioning.
-
Operates at: L7 (it must understand the API).
-
Knows about: routes, clients, auth, quotas.
-
Core value: managing a surface of many APIs/services.
The key differences
| Load balancer | API gateway | |
|---|---|---|
| Primary job | Distribute load | Manage & route API calls |
| Routes by | Health/load | Path, client, auth, version |
| Backends | Identical servers | Different services |
| Extra duties | Minimal | Auth, rate limit, aggregation, transform |
They’re not either/or
In practice they stack. Traffic hits a load balancer (distribution, availability), then an API gateway (auth, routing, rate limiting), which forwards to services — each of which may sit behind its own load balancer:
client → load balancer → API gateway → [LB → service A] / [LB → service B]
The interview cue
“A load balancer spreads traffic across identical instances; an API gateway is the managed front door for many services — auth, rate limiting, and routing in one place. I’d put a gateway in front of the microservices, with load balancing both in front of and behind it.” Knowing they complement rather than compete is the signal. (Gateway vs reverse proxy is the next fine distinction.)