An API gateway accepts API requests from a client, directs them to the appropriate services, and combines the results into a synchronous experience for the user.
What Is an API Gateway?
An API gateway takes all API calls from clients, then routes them to the appropriate microservice with request routing, composition, and protocol translation. Typically it handles a request by invoking multiple microservices and aggregating the results, to determine the best path. It can translate between web protocols and web‑unfriendly protocols that are used internally.
An e‑commerce site might use an API gateway to provide mobile clients with an endpoint for retrieving all product details with a single request. It invokes various services, like product info and reviews, and combines the results.
Videos on API Gateways
API Gateway Is Not the Same as Gateway API
The term API gateway describes a proxy (such as a reverse proxy or Ingress controller) that routes API calls to backend applications and can provide other services for API traffic, including – but not limited to – authentication, authorization, traffic shaping, and rate limiting. In short, it is a traffic management tool.
Conversely, the Gateway API is a conceptual evolution of the Ingress API, under development by the Kubernetes community. It is an API as opposed to a tool. In the future, we expect that implementations of the Gateway API (such as NGINX Kubernetes Gateway) will be able to act as an API gateway.
We discussed the difference between API gateway and Gateway API in depth at KubeCon 2022.
Building Microservices Using an API Gateway
For most microservices‑based applications, it makes sense to implement an API gateway, because it acts as a single entry point into the system. The API gateway is responsible for request routing, composition, and protocol translation, and can streamline the system. With an API gateway, each of the application’s clients gets a custom API. The API gateway handles some requests by simply routing them to the appropriate backend service, and handles others by invoking multiple backend services and aggregating the results. If there are failures in the backend services, the API gateway can mask them by returning cached or default data.
The Role of API Gateways in Microservices Architectures
An API gateway is the conductor that organizes the requests being processed by the microservices architecture to create a simplified experience for the user. It’s a translator, taking a client’s many requests and turning them into just one, to reduce the number of round trips between the client and application. An API gateway is set up in front of the microservices and becomes the entry point for every new request being executed by the app. It simplifies both the client implementations and the microservices app.