API Gateway

Give clients one entry point that routes requests to the right backend service and handles shared concerns like authentication and rate limits.

Description

Without a gateway, every client must know every service's address, and every service must implement authentication, TLS, rate limiting and logging itself. An API gateway sits at the edge and does this once: it routes each request by path or host to the right service, and applies cross-cutting policies on the way.

Clients see one stable API, and services can be split, merged or moved behind it without breaking them. Gateways can also aggregate calls, combining several backend responses into one, but keep that light: business logic doesn't belong in the gateway.

System design

HTTPS + token1validate token2/orders/*3/products/*4Web & mobileAPI gatewayauth · TLS · rate limitsIdentity providerOrders service/ordersCatalog service/products

API Gateway system design diagram

  1. Web & mobile (client).
  2. API gateway (gateway): auth · TLS · rate limits.
  3. Identity provider (external service).
  4. Orders service (service): /orders.
  5. Catalog service (service): /products.
  6. Step 1: Web & mobile → API gateway: HTTPS + token.
  7. Step 2: API gateway → Identity provider: validate token.
  8. Step 3: API gateway → Orders service: /orders/*.
  9. Step 4: API gateway → Catalog service: /products/*.
  1. Every client calls one address, the gateway, over HTTPS with a token.
  2. The gateway validates the token (signature check, or the identity provider) and applies rate limits before anything reaches a service.
  3. Requests for /orders are routed to the orders service.
  4. Requests for /products go to the catalog service. Services can move or split without clients changing anything.
AWS
Amazon API Gateway; Application Load Balancer with path routing; CloudFront in front.
Azure
Azure API Management; Application Gateway; Front Door.
Google Cloud
API Gateway; Apigee; Cloud Load Balancing with URL maps.

When to use it

Use it when

  • Several backend services sit behind one public or partner API.
  • You want authentication, TLS, rate limiting, CORS and request logging enforced in one place.
  • Backends will change (split, merge, migrate) and clients shouldn't notice.

Avoid it when

  • There's a single backend service. A load balancer is enough.
  • You'd use it to orchestrate business workflows. That logic belongs in services.
  • Ultra-low-latency internal traffic between services, where a service mesh fits better than a central hop.

Pitfalls

  • The gateway becoming a monolith full of per-endpoint logic owned by one team. Keep it to routing and policies.
  • A single point of failure. Run it highly available, and keep its configuration in version control.
  • Coupling every team's releases to gateway changes. Let teams own their routes, for example through configuration per service.
  • Added latency per hop. Measure it.

Alternatives

Backends for Frontends

Choose it when different clients (web, mobile, partners) need differently shaped APIs.

Service mesh

Choose it when the concern is traffic between internal services (mTLS, retries), not the public edge.

Load balancer

Choose it when you only need to spread traffic over instances of one service.

Facade

Choose it when the same idea inside one codebase: a simple front for a complex subsystem.