World of Microservices!!!

Veeranjaneya Gupta
6 min readJan 30, 2022

Microservices — Use Cases, Patterns by category

I have been hearing/working/experiencing microservices for last 10 years. But, I can answer only few questions about microservices like the advantages of microservices compare to monolithic or some microservices patterns. However, the fact is that I use lot of microservices patterns without knowing their details and I assume that the same case with many developers. After I looked into all the microservices patterns in a nutshell, I feel that I know the whole world of microservices and I would like to try to give the same experience with this article, let’s start..!

It is always important to know the pros and cons of Monolithic design before we start microservices because, every microservices pattern will try to resolve some challenge of monolithic use case.

Monolithic Architecture Pros & Cons

Quick definition of Microservices..

Microservices is an architecture style and the best way to learn microservices is to understand all the patterns but, there are 30+ patterns. So, it is good to categorize all the patterns and understand some of the popular patterns for each category.

In case of microservices, we create multiple smaller applications instead of a single monolithic application. But, on what basis, do we need to create these small applications..? The answer is Decomposition patterns and DDD(Domain Driven Design) is the best approach to create domain context and boundaries while creating the microservices. Let’s assume that we would like to build an insurance product and try to decompose it into small microservices.

  1. Decomposition Patterns :
Decomposition Patterns

For greenfield projects, we can use decompose patterns and create microservices directly because we get opportunity to start from scratch. In the above picture, we applied decompose patterns on Insurance monolithic project to migrate to smaller microservices. We can’t replace the Insurance monolithic project with the new microservices directly. It has to be done with a migration and we have refactoring patterns to do this kind of migration smooth.

2. Refactoring Patterns :

Refactoring Patterns

At this stage we are good to have microservices created and migrated from Monolithic application. In case of Monolithic, the communication between two services is like a call from one java method to another java method. But, in case of Microservices, the communication between two microservices comes with different challenges and we have communication/integration patterns to solve these challenges.

3. Communication/Integration Patterns : These patterns are helpful to build the communication between microservices and achieve the fault tolerance and resiliency.

Communication Patterns

Please refer my blog here to understand the API Gateway Pattern..

Below are the remaining integration patterns which helps to achieve the resiliency and fault tolerance for example, when a service is down and not to impact to other services and return some default response until the service is back to live.

Integration Patterns

At this stage, we have created microservices using decomposition patterns and established communication between microservices using communication patterns. But, how do we manage the data across multiple microservices and how do we manage the success and failures of transactions across microservices?. We have Database patterns to resolve the challenges with data and transaction management across microservices.

4. Database Patterns :

Database Patterns — Data Management
Database Patterns — Event Source Pattern

It is easy to do transaction management with Monolithic applications because, we can make multiple DB(Database) calls from a single DAO class and either commit or rollback the entire transaction easily based on the result. But, transaction management is challenging in case of microservices due to one DB for one microservice. So, we have Saga patterns to resolve the transaction challenges in case of microservices. Saga patterns are two types based on events and commands.

Saga Pattern — Events/Choreography Based
Saga Pattern — Orchestration/Command based

So far, we have solved the challenges occurred while creating microservices, to setup communication between microservices, and the data/transactions management with microservices. Still, we will have some more challenges with the microservices in terms of logging, tracing, etc.. In case of monolithic, it is easy with logging because all the logs can be generated from one application and store in one place. But, in case of microservices, some logs stored in data center if those microservices are running in the data center and some logs might store in the cloud because some microservices deployed into cloud and each microservice might have used different technology as well. So, to solve these kind of problems, we have observability patterns in the place.

5. Observability Patterns :

Observability Stack
Observability Patterns — Logging & Tracing

6. Cross Cutting Patterns : One last category of microservices patterns to resolve some of the common needs like..

externalized configuration to push config values dynamically to the services..

Canary Deployment to release the new version, test with some clients and make it available to all clients..

As microservices are best for horizontal scaling, we will have multiple instances deployed for every microservice and some of the servers are updated or added dynamically with the help of technologies like K8s..

So, service discovery is a problem when we have server IP addresses/instances getting changed dynamically.. In this case, we have service discovery pattern which allows you to create a service registry and capture all the changes of servers and IP addresses.

Cross Cutting Pattern — Service Discovery

At this stage, we have covered multiple use cases and microservices patterns with respective categories and it is time to look into the whole of Microservices together as a world..

Microservices Patterns

Congratulations.. you have read about most of the key microservices patterns with their categorization and I hope it gives you the best idea to look at microservices as a whole in the real time scenario. But, I request you to know about one another important concept that is anti patterns of microservices. It is must to understand anti patterns as well to not to get into tedious designs which worse than monolithic challenges. We have seen one anti pattern in the case of Database category that is Shared Database pattern. Here is the list of some more anti patterns..

Hope this blog is helpful, feel free to comment and Thank you very much!

--

--

Veeranjaneya Gupta

Developer, Engineering Manager & Technology Enthusiast!