In Microservices Architecture, we split a large, complex application into small, autonomous, independently deployable services. Therefore, it’s necessary to think about how to collaborate the data returned by each service. In IT industry, aggregator refers to a website or program that collects related items of data and displays them. So, in microservices the Aggregator Design Pattern is a service that receives a request, then makes requests of multiple services, combines the results and responds to the initiating request.
In Aggregator Pattern, there are 3 ways to implement it within Microservices application.
Explanation:
Assume you are a software engineer and your team has been assigned to develop a Microservices application for a University. However, they already
have a monolithic system and what you have to do is convert this monolithic system into a microservice application. Imagine you have to develop
4 services as follows,
When it comes to implementing, your team might create 1 microservice for each system, since that’s how we supposed to implement a microservices application. But the thing is, what happen when “Grading System” wants student information and marks information, or “Enrichment Program System” wants membership and achievements information?
So, what you can do is, create a service to consume “student information” and “marks information” services and give the response to the consumer that required (Grading System). Basically what happen is, the newly created service will take the request from the “Grading System” and invoked those 2 services to aggregate their responses and send it back to the “Grading System.” In Aggregator Pattern there are 2 ways to implement this solution.
This microservices pattern is a mix of Aggregator and Chain design patterns, that allows simultaneous request or response from two or more independent microservices. As you already know, a microservice may need to get the data from multiple sources including other microservices. The Branching Pattern extends the Aggregator Pattern and provides the flexibility to produce responses from multiple chains or single chain. This design pattern comes handy when you need to convert a large monolithic application into a microservices application. To get things clearer, check the following diagram.
As you can see, the service “X” is acting as the aggregator while it is branching out into 2 separate branches. The first branch contains an independent microservice (service “Y”) and second branch contains a chain of services, that has 2 microservices.
Benefits of using Aggregator Pattern