Bookmarks

API gateway

A server in front of a group of services through which clients reach their APIs: it routes requests to the right service and handles the shared concerns — access control, rate limits, metrics.

Also: gateway

checked 8 Nov

All terms

Without a gateway, every client knows the addresses of all the services, and each service checks tokens and enforces rate limits on its own. An API gateway brings these tasks together in one place: clients call a single address, and the gateway decides which service to pass each request to and what to check first. It also hides how the system is split into services: services can change without touching the clients.

What an API gateway does

  • Routing: uses the path, method or headers to decide which service handles a request; some requests pass through unchanged, others are split across several services.
  • Authentication and access control: checks tokens and keys once, at the entrance.
  • Traffic management: rate limits and quotas, protecting services from overload.
  • Aggregation: combines responses from several services into one, so the client makes a single request instead of several.
  • Protocol translation: the outside sees web-friendly HTTPS and JSON, while inside the services use whatever suits them, such as gRPC.
  • Observability: logging and metrics for every request; staged rollouts, such as canary releases.

Example

An online shop built as microservices — orders, basket, payments — puts a gateway at the entrance. The app always calls shop.example/api/…; the gateway checks the JWT, routes /orders to the orders service and /cart to the basket service, and assembles the product page from the responses of three services. It allows anonymous visitors ten requests per minute and authorised customers a thousand. The services know nothing about authentication or each other’s addresses.

The price to pay

A gateway is one more component to develop, deploy and monitor, plus an extra network hop on the path of every request. For most applications the cost of the hop is imperceptible, and large gateways handle hundreds of thousands of concurrent calls. Without a gateway, these same tasks would spread across all the services and clients.

Sources

the term is written from these pages

Verified 8 Nov

Not to be confused with

what it is mixed up with and how it differs

  • reverse proxy

    A reverse proxy merely passes requests to the backend; an API gateway does more — it manages requests: access control, rate limits, aggregation.

  • BFFbackend for frontend

    BFF is a variation of the API gateway: a dedicated gateway per client type instead of one shared by all.

  • service mesh

    An API gateway is the entry point for external clients; a service mesh manages traffic between the services themselves, inside the system.

In depth in the references

where the topic is covered in detail