What is an API gateway, and how is it different from a load balancer?
The single front door of a system with many services: it checks who you are, how much you're asking for and where your request should go, before any service sees it.
In one sentence
An API gateway is one entry point for all your APIs. It handles the cross-cutting work (TLS, authentication, rate limiting, routing, logging) once, so each service only does its own job.
The problem: many services, many doors
With a monolith there's one server to call. Split it into users, orders, videos and payments, and suddenly every client needs four addresses, and every service has to validate tokens, limit abuse and log requests. Four copies of the same security code, drifting apart.
What a gateway does
- Routing:
/orders/*to the orders service,/videos/*to videos, by path, host or header. - Authentication: validates the JWT or API key once and passes the user ID to the services.
- Rate limiting and quotas: per user, per API key or per plan.
- TLS termination, CORS, compression and caching of simple responses.
- Request shaping: adding headers, versioning (
/v1,/v2), sometimes combining several service calls into one response. - Observability: one place to log, measure latency and trace every request.
Gateway vs load balancer
| Load balancer | API gateway | |
|---|---|---|
| Main job | Spread traffic over copies of the same service | Decide what a request may do and which service gets it |
| Understands | Connections (L4) or HTTP basics (L7) | Your API: routes, users, keys, plans |
| Typical features | Health checks, algorithms, TLS | Auth, rate limits, quotas, transformations |
| Examples | AWS ALB/NLB, NGINX, HAProxy | AWS API Gateway, Kong, Apigee, Envoy-based gateways |
They often work together: client → gateway → load balancer → instances of a service. Modern L7 proxies blur the line, but the question in an interview is the same: where do auth, limits and routing live?
Keep it thin
- Every request passes through it: run several instances so it isn't a single point of failure.
- It adds a hop: a few milliseconds of latency.
- Don't move business logic into it. Routing and policy, yes; "apply a discount if…", no.
- A Backend for Frontend (BFF) is a variant: one gateway per client type (web, mobile) shaped for its screens.
Key takeaways
- 01An API gateway is the single entry point that handles auth, limits, routing and logging once.
- 02Services stay simpler and consistent because cross-cutting concerns live in one place.
- 03A load balancer spreads load over copies; a gateway decides what a request may do and where it goes.
- 04Run it redundantly and keep business logic out of it.
Check your understanding
1 of 3
What is an API gateway?
Related concepts
Load balancers
A load balancer is the single entry point that receives every request and forwards it to one of many healthy servers, so no single server is overloaded and failures stay invisible to users.
8 min read →Rate limiting
A rate limiter caps how many requests a client can make in a period ("100 per minute") and answers the rest with 429 Too Many Requests, so one client can't take the system down for everyone.
6 min read →AWS Lambda
AWS Lambda runs a function only when an event arrives, scales to many copies by itself and bills per millisecond, but each run is capped at 10 GB of memory and 15 minutes.
8 min read →