Design patterns for Microservices Architecture.

Bavatharany Mahathevan
3 min readNov 30, 2021

--

As a result of understanding the microservice architecture from Introduction to Microservice Architecture, I hope that you understood the concept of microservice architecture over the monolithic architecture and you are able to choose the appropriate architecture for your problem. In this article, we are going to discuss the design pattern for microservice architecture.

There are mainly three types of design patterns in microservices architecture which are :

  1. Aggregater design pattern
  2. Proxy design pattern
  3. circuit design pattern

Aggregater design pattern

Let's start with the definition of a microservice architecture by Martin Fowler

In short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API.

by : Martin Fowler

As you know, microservice architecture is a combination of multiple independent services and each service have a separate database. And those services would communicate within them by a well-defined interface(REST API). Suppose, when we need a collection data or combine data from multiple services, then we can use the aggregate design pattern.

The aggregate design pattern seems like the web application that retrieves data from multiple services and displays the data on a single web page after some logic process.

Aggregator Microservice collects pieces of data from various microservices and returns an aggregate for processing.

The aggregation is achieved mainly in three ways.

  1. Scatter Gather/Parallel Aggregation pattern
  2. Chained pattern
  3. Branch pattern

To understand this stuff, let's go with the Airline system.

Assume that, we are going to develop a system for Airline service in Microservice Architecture and Imagine you have to develop 4 services as follows,

· service A : Passenger Information

· service B : Pilot Information

· service C : Invoice and billing Information

· service D : Timetable Information

Moreover, you have systems named passenger management system and travel management system for these 4 services.

  1. Scatter Gather/Parallel Aggregation pattern

When the Travel management service needs service /data from the Pilot service and the timetable service, In parallel aggregation, the response comes from both services parallelly and provides a combined response to the aggregator service. The Aggregator service is responsible for providing a processed response to the Travel management system.

Scatter Gather

2. Chained Pattern

What would happen when the Pilot Information service depends on the information/data of the TimeTable service? For example, to check the availablily of a pilot at a particular time. In this case, we can not get a response from those two services parallelly.

Here, we must invoke the timetable information and get a unique time then pass it to the Pilot service and return the available pilot for the given time.

Chained Pattern

Branch Pattern

Branch patter is an associate of the parallel and the chained pattern. suppose a new requirement, The travel management system needs the service from the Pilot Information service, TimeTable service and the passenger service. As the Timetable service depends on the pilot information, the response can be returned from a chain pattern and its response and other service passengers information will be invoked in a parallel pattern and provides the response into a new aggregated service.

Branch Pattern

Reference :

https://dzone.com/articles/microservice-design-patterns

https://www.javacodegeeks.com/2015/04/microservice-design-patterns.html

--

--