Sitemap

Microservice

4 min readJul 19, 2022

--

Design Patterns for Microservices

Aggregator pattern

Three ways of implementation are there.

  • Parallel (Scatter gather pattern)
  • Chain Pattern
  • Branch Pattern

Consider this example,

For a company It need to create a system based on microservice.

1. Service to get person’s information. ( employee)

2. Service to get leave information.

3. Service to get apparel information.

4. Service to get allocation information. (work field… )

Also need attendance management system and project management system.

Also the company has monolithical system with all given things. Here we need to convert it to microservice system.

So, As we talked already ‘Do one Do it well’ through this words, create each services to each required work.

If the system needs two things at the same time. That’s fine to do. For 4 services we can create 4 docker or multiple based on the demand and deploy this.

If Attendance system need two services personal information service and leave information service. Solution is create one service to consume those microservices to response back to consumer.

Press enter or click to view image in full size

getting response from person information service and Leave information service and aggregate those as a single response and send it to consumer is called as parallel pattern.

leave information have dependency from personal information.

Get Vetharsana Thangarajah’s stories in your inbox

Join Medium for free to get updates from this writer.

If the consumer send employee Id , service invoke personal information service with employee Id and get Employee code as response and invoke leave information service with employee code and get response then aggregate and send the response to consumer. This pattern of work is called as Chain pattern.

As a different between Parallel and Chain patterns response time is there.

In Parallel , created service invoke both services (person information service and leave information service) at the same time. but In Chain it invoke one by one.

Branching — If a consumer sends employee Id and Branch code First the service invoke personal information service and through that it find the work branch and pull the work allocation in work allocation to that employee Id.

if the project requirement change that is not a problem. Because no need of existing services. we can create new services. also all services are independent in microservices.

Circuit Breaker Pattern

Consider power circuit around our home and when you see the circuit main box there will be a circuit breaker which helps to break the additional power. Likewise This pattern is working in microservices to protect our services.

What are the causes break the service?

Press enter or click to view image in full size

When web server or other sends request and a service that needed is get little delay to response. so the request is in waiting in thread.

Press enter or click to view image in full size

If more than one requests come from server Threads also get filled and wait and the applications are get delay to response. remaining requests will be blocked and queued. service system will process queue. Also so the It will not recover because more and more requests will come to the queue.

This is called as cascade failure.

Press enter or click to view image in full size

The solution, If no response with in the time limit cut off the connection. but in the background there is a one thing called ping. if the service gives signal, it will connect back.

Proxy Pattern

Consider, your company has monolithic applications. you need to migrate it to microservice architecture. So need to deploy services part by part. when do this continuously , need to change some services.

For example,

consumer ends employee code to get leave information. But you created new service as a new version of existing service. Here because of the new version update consumer need to send employee Id where they may break because they don’t how to pass.

Here we will use proxy pattern. Proxy service will be created as shown below and if consumer sends employee code it will direct it to old service. if send employee Id it will direct it to new version of service.

Press enter or click to view image in full size

--

--

Vetharsana Thangarajah
Vetharsana Thangarajah

Written by Vetharsana Thangarajah

I am Computer Science graduate, worked as an Associate Software Engineer - Java at Virtusa for 3 years. looking for a job to continue my career in Canada.