DESIGN PATTERN FOR MICROSERVICES — AGGREGATOR PATTERN

Aggregator Pattern

Kavindaperera
3 min readMar 26, 2022

One of the most famous topic is microservice . Microservice is considered as famous architecture nowadays as it has become the most favorable choice for modern application. The majority of applications were switched from monolithic to microservices architecture . Each of these architectures has its benefits as well as drawbacks. If you are new to microservices, you can refer to my article Introduction to microservices.

Why do we require design patterns in microservices?

The whole decision of whether your application is running smoothly through microservice architecture depends on the way you design. Thus, design pattern plays a significant role. There are several design patterns available in microservices, and we will discuss each of them and the benefits of every design pattern. Choosing the most appropriate design pattern is the essential factor; otherwise, it will shut down your application.

Aggregator Pattern

This design pattern is considered the main design pattern. The aggregator design pattern is simply a service that receives a request, then makes requests of multiple services, combines the results, and responds to the initiating request. Aggregator pattern has three different branches or three different ways you can implement an aggregator pattern.

Three types of aggregator pattern

Three types of aggregator pattern -

  • Parallel (scatter-gather pattern)
  • Service chaining or chain pattern
  • Branch

To explain the microservices, let’s consider an example. Let’s assume that we are a developer and we have been asked to create a microservice application for a school. We were required to expand their business from monolithically to microservice architecture.

Service 1 : Get student personal information

Service 2: Get Student absence information

Service 3: Get Student Marks and related information

Service 4 : Get Achievements including extra curricular activity information

Additionally, you have two consumers named Grading System and Student Rank System.

There are plenty of ways to move this from monolithic application to microservice application.

ISSUE- When it comes to microservice implementation, just one service per system is created independent of each other. But now, the problem is raised as the grading system requires students’ personal information and student marks information. The student rank system requires information from student personal information and student absence information; therefore, how can we solve this?

In Aggregator Pattern there are 2 ways to implement this solution.

Solution 1 When the grading system service has been invoked it simply sends out two parallel request to student information and student marks information service. When the response from the student information and student marks information is received it simply aggreges the response into one single response and then forward it back to the grading system. This particular pattern is known as scatter gather pattern

Solution 2- If there is any dependency between the two services then we cannot send the request parallelly in other words we cannot use scatter gather pattern. Lets assume that the student mark service has to wait until it receives a response from the personal information service. In this particular case we can simply send the request to the student personal information and get the student id along with the response and then pass the student id to the marks information service and get the related information . once the information is achieved it simply sends back the response to the grading system. The second solution is known as chained pattern

Branching Pattern- This design pattern comes in handy when you require to convert a large monolithically application to a microservice application. The microservice may require to obtain data from multiple sources including other microservices. The branching pattern extends the Aggregator pattern providing the flexibility to produce responses from multiple chain or single chain

Benefits of using aggregator pattern

  • Easy to understand and implement
  • Scalability
  • Microservices signature flexibility to internal services

Thanks for reading the article hope you enjoyed it. If you do require any additional support for code, go through my GitHub link — https://github.com/KavindaPereraa/

References

Web application to Microservices. GO or NO GO — YouTube

What are Microservices? | SmartBear

What are microservices?

--

--