Skip to content
System Design Explorer
networking

API Gateway

By Ankur NayakReviewed

An API gateway is the single front door to a set of backend services. It routes each request to the right service and handles cross-cutting concerns such as authentication, rate limiting, retries and protocol translation in one place.

API Gateway diagramComponents: Mobile App, API Gateway, User Service, Order Service, Search Service. Connections: Mobile App to API Gateway; API Gateway to User Service (/users/*); API Gateway to Order Service (/orders/*); API Gateway to Search Service (/search).Mobile AppClientAPI GatewayAPI gatewayUser ServiceServiceOrder ServiceServiceSearch ServiceService
Gateway routing

How it works

Without a gateway, every client must know the address of every service and every service must re-implement authentication, throttling and logging. A gateway centralises that edge logic: clients call one host, and the gateway forwards each request to the right internal service.

Typical gateway work includes TLS termination, authentication and authorization, rate limiting, request validation, routing by path or header, retries with timeouts, circuit breaking and translating between external formats (JSON over HTTP) and internal ones (gRPC, Thrift).

Some gateways also aggregate: one client call fans out to several services and returns a combined response, which saves mobile clients many round trips. This is sometimes called the backend-for-frontend pattern.

Key points

  • One entry point; services stay private
  • Central place for auth, rate limiting and observability
  • Can translate protocols and aggregate responses
  • Must be horizontally scalable and highly available, since everything goes through it

When to use it, and pitfalls

Use it for

  • Microservice architectures exposed to external clients
  • Mobile apps that benefit from aggregated, client-specific APIs

Watch out for

  • Business logic creeping into the gateway, turning it into a monolith
  • Added latency on every request if filters are heavy
  • A misconfiguration can take down every API at once; roll out config gradually

Trade-offs

One gateway vs. one per client type

Use a shared gateway for routing and policy, plus thin backends-for-frontends where clients diverge.

Pros: Shared policy in one place; Client-specific aggregation without bloating the core gateway

Cons: More components to run

Used in

Frequently asked questions

Is an API gateway the same as a reverse proxy?

A gateway is a reverse proxy with API-specific features. A plain reverse proxy forwards and balances traffic; a gateway adds authentication, rate limiting, request transformation, API keys, analytics and often response aggregation.

Where should rate limiting happen?

At the edge, in the gateway, so abusive traffic is rejected before it reaches any service. Services can still keep their own limits to protect expensive resources such as a database.

Sources