Microservices

microservices.jpg

Originally Posted On....

There are many such issues as the size of the application increases, and become difficult to reason about, especially when a new team member is working on it. Sometimes you feel for the particular task that the other technology can achieve very easily which we are not using in our project. Most of these drawbacks are coming from the Monolithic architecture. Where all the functionalities exist in a single codebase. For example, arranging out applications in various layers like presentation, service, and database manipulation. This is what exactly defines the monolithic application.

Are you experiencing difficulties in managing your code?
Are you redeploying the whole application even for a small change?
There are many such issues as the size of the application increases, and become difficult to reason about, especially when a new team member is working on it. Sometimes you feel for the particular task that the other technology can achieve very easily which we are not using in our project. Most of these drawbacks are coming from the Monolithic architecture. Where all the functionalities exist in a single codebase. For example, arranging out applications in various layers like presentation, service, and database manipulation. This is what exactly defines the monolithic application.

Let me describe some drawbacks of monolithic architecture, then we will understand how microservices help us to overcome those drawbacks.

  • Difficult to adopt new technology.
  • Not reliable as a single bug can bring the whole application down.
  • Difficult to understand as the application grows large.
  • Time-consuming in the context of managing the code cohesion and for maintenance too.

So, those are the disadvantages where microservices come into the picture.

What are microservices?

In simple words, Microservices are small, autonomous services that work together. Ok, let's break down this definition and understand it more precisely.

"Microservices are small" so there is no perfect measurement stated in any book that how small is small. But yes there are a few conventions that help to make our microservices as small as possible. Like it follows the Single Responsibility Principle. This simply means that a service should be responsible for doing one task only and doing it very well. Moreover, focusing on service boundaries on business boundaries, makes it clear where the code is located for the specific functionality.

autonomous services that work together" what this sentence mean is we should be able to change our service without requiring the consumer to change. One should think very carefully about what should be exposed and what should be hidden by the service. If one service needs to change and that change it requires additional coordination with other services then it is not an ideal situation. This decreases the autonomy. Services should be able to change independently of each other.

microservice2.PNG

Benefits of microservices:
Technology Heterogeneity: This makes it possible to compose a system with microservices each one is implemented in different technology. It takes advantage of picking the right tool for the right job. As we can consider the case where if a specific type of data is stored in a specific type of database then system performance can improve. For example:

Resilience: In a monolithic system when service fails, everything stops working. Under microservice architecture, we can manage that if one component of the system fails and it doesn't cascade then you can isolate the issue and the rest of the system can carry on working.

Ease of deployment: As in monolithic applications one line change requires the whole application to be deployed again to release the change. While in microservices, we have the advantage of deploying a single service independently which carries the change and need not worry for the rest of the system.

Scaling: Obviously scaling everything as a piece is a tedious task to do. But this is not the case with microservices. We can scale those services which require scaling while it allows us to run other services on less powerful hardware.

Smaller codebase: In a microservice architecture, it is possible to allocate a team for a particular service. And a smaller codebase makes the code clean and easy to understand for the team and newcomers also.

There are many more key benefits of microservices that are beyond this blog, though one should be careful before adopting microservice architecture with some of the drawbacks which should be taken care of.

Let me list out a few disadvantages here, Microservices communicate with each other via network calls, which may increase the latency.

Moreover, tracing the source of failure is difficult in microservices as each microservice has its own set of logs. This makes debugging more challenging.

Application cost may rise with the microservices as it requires sufficient hosting infrastructure with security and maintenance support. An organization may have to acquire a team who can analyze and manage the services.

Conclusion
In my opinion, an organization can adopt the microservice architecture if they are willing to develop applications in a distributed environment. However monolithic architecture is also a good fit for small-scale organizations where the number of users of an application is going to be limited. But, when there are requirements like scaling, high modularity, and negligible downtime microservices architecture can be a good choice.

Get In Touch With Us To Know More...