Discover more from Awesome Software Engineer
The Path to Microservices: API Gateway Aggregation Pattern
API Gateway Aggregation Pattern and Backend for Frontend
Microservices architecture split the whole system into different services which allows us to scale each service independently. But, it brings some problems to the architecture as well. For example, multiple entry points. Since we split the system into multiple services, the data is distributed across different services. If a client wants to get data that is stored in different services and assemble the data for a page, the client needs to call different endpoints to aggregate the data they need. Also, we need to expose all the services to the internet.
Do you know what is the problem with this design? Think about it.
From the above use case, we can find:
The client needs to manage different endpoints to assemble data
Hard to manage security control due to multiple entry points
Expose the business domains to the public
Increase request overhead due to coarse-grained API and multiple HTTP requests
To solve this problem, API Gateway Aggregation Pattern comes into play. Now, we can introduce an API gateway in front of our internal microservices and only expose the API gateway to the internet. By using this approach, the client will only talk to the API gateway. That said, the client does not need to manage multiple entry points anymore. The API gateway serves as a middle layer to help aggregate the data from different microservices and provide fine-grained APIs to the client. Also, we can implement security control in this layer to validate data, user identity, rate control, etc.
Apart from the API Gateway Aggregation Pattern, there is a variation called Backend for Frontend (BFF). The reason why we need this variation is that we might have different types of clients in a system such as a web, mobile, and public API. These clients might need different data even for the same feature. So, we can introduce different “API Gateways“ to serve different clients. Then, we can control the API granularity and functionality in different clients.
If now your manager asks you to create an API platform for external system integration, what will you do?
Thanks for reading Awesome Software Engineer! Subscribe for free to receive new posts and support my work.