Definition of the API gateway
An API gateway (passerelle d’API in French) is a software component placed between client applications and the services they call. Clients know only the gateway: it receives their calls and forwards them to the relevant services. The notion is one of common usage: it can be found in published architecture patterns and in vendor documentation.
On the microservices.io website, Chris Richardson ties the “API gateway” pattern to microservices architecture and describes it as a single entry point for all clients: the gateway relays some requests to one service and answers others by querying several services. The Microsoft Azure Architecture Center gives a similar reading: a centralised entry point, which acts as a reverse proxy and can handle cross-cutting tasks.
What the gateway spares clients and services
Without a gateway, every client addresses every service. The Microsoft page lists the consequences: more complex client code, tied to the internal breakdown of the application, multiplied network round trips for a single operation, and authentication or encryption to be handled in each exposed service.
The microservices.io page adds that the breakdown into services may change and is best kept hidden from clients. During a step-by-step overhaul, a gateway can play the role of the routing facade presented on our page on application modernisation.
Routing, aggregation, offloading: the functions of an API gateway
The Microsoft documentation sorts the uses into three patterns.
- Routing (gateway routing): the gateway directs each request to the intended service, based on its application content (layer 7).
- Aggregation (gateway aggregation): the client sends a single request, the gateway calls several services and assembles their responses.
- Offloading (gateway offloading): cross-cutting functions are provided once for all services, for example TLS termination, mutual TLS, authentication, rate limiting or logging.
API gateway, reverse proxy, load balancer, service mesh, API management: not to be confused
These terms are ones of common usage, and their scopes overlap from one product to another.
| Notion | What it refers to | Relationship with the gateway |
|---|---|---|
| Reverse proxy | An intermediary server that receives requests in place of the application servers, such as NGINX or HAProxy | The gateway is one, specialised in APIs |
| Load balancer | Distributing requests between the instances of the same service | Depending on the product, the gateway provides it or relies on an adjacent load balancer |
| Service mesh | A layer of network proxies that manages exchanges between services, such as Istio or Linkerd | The gateway handles calls coming from clients, the mesh internal exchanges |
| API management | The discipline and tooling of the API lifecycle | The gateway is its runtime component |
Inventory, developer portal and versioning policy are described in the API management entry.
The limitations of a mandatory passage point
The microservices.io page notes two drawbacks: one more component to develop, deploy and operate, and a response time lengthened by an additional network hop. The gateway’s position can create a third: all calls go through it, and its unavailability can cut off access to all services. The same page provides for it to call services through a circuit breaker.
Example: an insurer’s customer area
Imagine a home insurer whose customer area exists as a website and as a mobile application. Policies, claims and payments are served by three separate services. The mobile application calls a single address, that of the gateway. The gateway checks the access token, applies the call quota set for the application, then routes the request. For the home screen, it queries the three services and returns an assembled response.
If the claims service is split in two, only the routing rules change: the mobile application does not have to be republished.
Where to place a gateway, how many to deploy, which business rules to keep out of it: these decisions fall within IT architecture, whose page details the integration rules.