System Design Playbook
17 · Communication5 min read

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.

One door for every request
ClientAPI gatewayTLSAuthRate limitRouterUsersOrdersVideos
Served (200)
0
Rejected
0
Places that check auth
1
Services
3
The gateway terminates TLS, checks the token, applies rate limits and routes by path, once, before any service sees the request. Bad requests never reach your services.
Send valid and invalid requests through the gateway, then switch it off and see each service doing the same checks on its own.

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 balancerAPI gateway
Main jobSpread traffic over copies of the same serviceDecide what a request may do and which service gets it
UnderstandsConnections (L4) or HTTP basics (L7)Your API: routes, users, keys, plans
Typical featuresHealth checks, algorithms, TLSAuth, rate limits, quotas, transformations
ExamplesAWS ALB/NLB, NGINX, HAProxyAWS 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