You are currently viewing Understanding Microservices

Understanding Microservices

In this section, I will share my understanding of Microservices, what problem does it solve and how to migrate an existing monolith application to this architecture.

What is Microservice

Microservice is an architecture and organizational approcah to develop softwares where software is composed of small independent services, which communicate with each other in loosely coupled manner. In this approach, small dedicated teams can be formed for one or more than one service, and those teams are responsible for the devlopment of their dedicated services. Since services are loosely coupled, so team does not depends on other team(s) in order to complete their service.

What is Monolith Application

Monolith application are opposite of Microservices. In this approach many components which are strongly coupled with each other are packaged in one piece.

Drawback of Monolith Application

Few draw back of “monolith” applications are given below. We need to understand it in detail, since these are the problems which are addressed in the Microservices.

Reliability

Reliability is one of the major draw back of the monolith application. Any fatal error in any part of the application will crash the entire system. Its reason is that monolith application are deveoloped in strongly coupled manner.

Deployments and Updates

If you made a single change in the application, you need to push the entire application on deployment. There is no way to deploy a single change of a particular module on production. 

Since, in monotlitic application, components are strongly coupled and they directly communcate with each other, so change in one component may require to change in other components.

Technology Stack

Monolith application are developed using a single technology stack. So in order to fill the resource gap, you need to find the resource of the same technology stack.

Large Code Base

Since monolith application are built using strongly coupled modules which directly communicate withe each other, so with the passage of time and with the increase of product complexity, the code base also increases and it takes much time for any new joiners to understand the large code base.

Benefits of Microservices

Microservices offer many benefits over the monolitic application and it almost addressed all the problems/draw back of the monolitic applications. These benifits are given below:-

Deployments

Microservices can be deployed independentely. Since these are deployed independentely, so if there is a change in one microservice, it can be deployed individually instead of deployed all other services. e.g. In real life microservices are packages into docker image, and the containers are run by using the docker image. 

Scalability

In microservices, we can scale services based on the laod which each microservice receives. e.g. If our system consists on 5 services and we found out that our two services i.e. Service X and Service Y are always overloaded, then we can scale out only these two services. While in monolitic approach, if a single module is overloaded, we need to do the horizontal or vertical scalling. 

Fault Tolerance

Microservices offers better fault tolerance as they are developed by providing the fall back strategies when certain services fails.

Small Code Base

Each service in Microservices consistes on reasonable small code base, so it is easy for any new joiners to understand the code, domain and business of that service.

Different Technology Stack

Each Microservice in Microservices can be developed in different technology stack. It is not compulsory to develop all the services using a single technology stack. So we can have a service using ASP.Net Core, a service using Node.JS, a Service using python and so on. 

Asynchronous Communication

Microservices can communicate with each other using asynchronous manner. But it does not mean that they always communicate with each other using asynchronously. Microservice communicate with each other asynchronously in order to reduce tight coupling. 

If your services are communcating with each other synchronously, it means that we are inducting the coupling. In that case, we need to add some fault tolerance as well such as fall back and circuit breaker pattern.

Drawback of Microservices

As we have seen that there some benefits of microservices, but there are also some drawback of the microservices. Microservices based application are more complex to design and develop. 

More teams are required and it requires changes in how teams and organization works. Microservices based application are often more expensive to build.

Migration from Monolithic to Microservices

It is one of the most common question being asked i.e. “How to migrate an existing monolithic application to Microservices”. The answer to this question is “Strangler Application pattern”. In this pattern, a new application is build around the existing monolith application and this new applicationis called “Strangler Application”. This application incrimentally replace the old feature with the new service and once the new service is inducted, the old monolitic component for that particular service is decommissioned. So after each iteration, the size of the monolith application shrinks, and ideally after n number of iteration, the whole application is replaced with the new one. Graphically, it can be depicted as follow:-

Strangler Application

Conclusion

Like any other design, we can not starting building a microservices based application blindly. It has many advantages, but on the other hand its expensive and complex to build. It also requires changes in how an organization and their teams works. 

Leave a Reply