Aggregator Pattern
- TechTutor
- Oct 23, 2023
- 3 min read
Assume you have 100 microservices and your web application wants to display consumers a consolidated report by aggregating data from several microservices. As a result, your client application searches microservices and consolidates data at the end to provide to end users. This strategy may cause performance concerns because the client must query each microservice to obtain relevant data and aggregate it at the end.
The aggregator design pattern defines a service that receives a request, then sends many requests to other services, combines the results, and then responds to the initial request.
Choosing the right design pattern for your microservices architecture determines whether or not your application will work. For microservices architecture, there are numerous design patterns accessible. As a result, you must select the appropriate one, as it will greatly help you. However, if you do not select the appropriate design pattern for your situation, the entire system will be unstable and perform poorly.
We divide a huge, complex application into small, autonomous, independently deployable services in Microservices Architecture. As a result, it is vital to consider how to collaborate the data given by each service. The Aggregator Design Pattern in microservices refers to a service that accepts a request, then makes requests of various services, combines the results, and answers to the initial request.
In Aggregator Pattern, there are 3 ways to implement it within Microservices application.
1. Parallel aggregation (Scatter gather pattern)
In Parallel aggregation, requests are sent to necessary services parallelly. Then the responses are aggregated and the response is sent back to the consumer. Scatter Gather Pattern helps us to distribute these tasks to achieve parallel processing of tasks/messages/events & finally aggregate the responses as a single response as shown above.

2. Chain pattern (Service chaining)
Unlike parallel aggregation in the chain, pattern requests are not sent to services parallelly. Assume there are 3 services named A, B and C implement with chain pattern (As in diagram below). How it works according to chain pattern is, consumer first sends the request to service A, then service A sends a request to B to and finally to service B sends a request to service C (consumer > A > B > C). The best practice is to keep the chain length to a minimum.

3. Branching pattern
Branching Pattern microservices pattern is a hybrid of Aggregator and Chain design patterns that allows two or more independent microservices to request or respond at the same time. As you are aware, a microservice may require data from numerous sources, including other microservices. The Branching Pattern enhances the Aggregator Pattern by allowing answers to be generated from several chains or a single chain. This design pattern is useful for converting a large monolithic application to a microservices one. Check out the diagram below to help you understand.

As you can see, the service “1” is acting as the aggregator while it is branching out into 2 separate branches. The first branch contains an independent microservice (service “2”) and second branch contains a chain of services, that has 2 microservices.
Summary
The Aggregator Pattern in microservices is a design approach where a central service, known as the aggregator, collects and combines data from multiple microservices to provide a unified and aggregated response to the client. This pattern is used to simplify client interactions by reducing the number of requests and enhancing performance. The aggregator service fetches data from various microservices and assembles it into a single, cohesive response, offering clients a consolidated view of information. It's a valuable solution for improving efficiency and reducing the complexity of client-server interactions in a microservices architecture.