A microservice based application can have multiple services, each performing a unique individual task. A client to the application may require combinations of data obtained from each of those microservices. Microservices usually provide fine-grained APIs, which means that the client would need to interact with every individual microservice of interest.
Different consumers of the application would require different combinations and formats of the responses. The microservices themselves might support different protocols, making communication more complex. Also, the latency requirements of the consumers themselves would affect their experience with the application.
In a practical scenario, the service partitioning could change over time, and it is in the interest of usability that such changes are masked from the consumer.
Thus, it becomes necessary to provide a single point of access to the application for any microservice API call. This provides the background for the API Gateway Pattern.
The API Gateway Pattern
The API Gateway is usually an entry-point to the system. It may store partial responses from microservices, as it waits for responses from other services. It solves the following issues:
- Accessing data from microservices over different protocols
- Access privileges for data
- Data format management
This pattern works as a proxy that forwards requests to relevant services. It can play a vital role in assisting Authentication and Authorization.
Advantages of the API Gateway Pattern
- Single Point of entry, acting as a proxy, abstracting the producer details.
- Can request data from multiple microservices, aggregate the data and deliver the results to the consumer.
- Can do protocol conversions (like MQTT to HTTP)
- Can expose client-specific API.
Examples of situations where this may be required can be found in .
Online Code Examples
 DZone on the API Gateway Pattern: https://dzone.com/articles/design-patterns-for-microservices
 API Gateway Pattern: https://microservices.io/patterns/apigateway.html
 API Gateway vs. Aggregator: https://stackoverflow.com/questions/68044745/api-gateway-pattern-vs-aggregator-pattern-in-the-context-of-microservices
 DZone on the API Gateway: https://dzone.com/articles/microservice-pattern-api-gateway