Introducing Microservices

Introducing Microservices

Hello, Hello, Hello ~ welcome to this new blog. In this blog I am going to explain about Microservices so sit back relax and keep your focus on and let's get started.

A modern software application yo wanted to perform well

Introduction to Microservices

Microservices is an architecture style that is grown rapidly and gain popularity over the last decade it has ability to achieve the goals of modern software application.

What are Microservices ?

So what is really mean by Microservices? Let's answer this question.

A Microservice is an architecture style where autonomous, independently deployable services collaborate together to form a border software application or system.

image.png

That's it, as simple as that, you might even worked on system that follow this approach without calling it microservices architecture.

In the name of microservices itself, suggests that the services should be small but their is no any such size limit this is depended on the developer that how much larger or smaller he wants to build it so that it can follow the microservices approach.

Now the question here generated is why? Why do we even need microservices?

To answer this question we have to understand what is monolith and what is the problem of monolith.

Monolith Architecture

Before microservices we were using monolith architecture to develop the application. The application who follows monolith architecture has :-

  • Single codebase :- Monolith application typically has all of it's code in a single codebase, All the developers collaborate together in the same code repository
  • Single process :- The build artifact is usually a single executable or process that runs on a single host server or virtual machine and persist all of it's data in a single database.
  • Consistent technology :- The development environment typically uses a single consistent technology, such a s what programming language or SDKs using throughout the codebase.

Monolith Benefits

  • Simplicity :- The code is in the one place so it's Easy to find things, there is only one thing to build and run, so it is straight forward for developers to work on
  • Deployment :- When it comes to deploy the monolith to production there is only one single application to deploy and if in future we have to update the version then also we just have to replace only one application.

Remember just because now a days we uses microservices more than monolith that doesn't mean there is something wrong with the monolith approach if everything is working fine and great for you think twice Do you really need microservices just because world is using it. If in your organization everything is good while following monolith you should stick with it. in my opinion. until you are really facing problems due to monolith.

The problem with monolith

The problem of scale :-

The problem of monolith is when it comes to scale, Monolith model works well with single developers or a small teams who is working togethers just for 2 to 3 months may be to build a small website that handles a modest numbers of visitors.

What happens when our project grows much larger ?

image.png

Let's assume if we got 20 to 30 developers who are working for the period of several years building a system that have 1000s of users and stores massive amount of data.

In this kind of situation monolith approach becomes a big problem .

As a codebase grows larger there is a tendency to become more difficult to maintain due to growing complexity and the accumulation of technical debt.

Even if you made a concretive effort to keep your monolith modularized often you will find that these module end up becoming very entangled and interdependent.

Problem in Deployment :-

When it comes to deploy the monolith even a single line code change requires entire application to be deployed which is risky and usually involves a period of downtime which is unacceptable in the modern era of cloud services that are expected to maintain high availability.

Difficult to scale :-

Scaling of monolith to meet demands of increased usage or large amount of data is also very difficult, unless great care has been taken to make your monolith stateless you probably can't scale it horizontally. So the only option is to scale vertically where you provision much more powerful and expensive service . A monolith application requires entire application to be scaled out together rather than just scaling the component that actually need extra processing power.

Wedded to legacy technology :-

With the monolith you can very easily find yourself wedded to legacy technology, The technology you have used to build the original application version is going to be very hard to get away from in the monolith applications, as you have to upgrade the entire application to move to newer framework. And this reduces your agility to adapt newer patterns and practices, and also taking advantage of new innovation such as new tools and services that would benefit your application.

Distributed Monolith

Now you may be thinking that my application is not monolith it is made up several services that runs on different hosts and talk to each other over the network.

REMEMBER :- Just because your application architecture is based on services doesn't mean that you are using microservices.

It is possible to create a system where you have several services but they all access data in a shared database. and they are tightly coupled to each other in such a way that you have to deploy them all together. And any change you make to the system requires modification to multiple services.

image.png

System like this are sometimes referred to as Distributed Monoliths and these things are big trouble because it may combine all the downsides of monoliths and all the challenges of microservices and offers very few of the benefits of the either approach.

that's why it is very important to have a clear understanding of microservices before diving into creating them or you could end up using Distributed Monoliths and wake up in the world of pain🥲

The Benefits of Microservices

We have already looked at the drawbacks of monoliths, now let's take a look at the benefits of microservices.

image.png

  • Small Services :- By breaking down our application in smaller pieces each microservice can be owned by a small development team, and it is much easier to understand and work on. The best thing of the service to be small enough that it can be thrown away or rewritten if necessary.

  • Technology Choice :- Microservice allow us freedom to adopt new technology without needing to upgrade everything in one go, and gives us the flexibility to use the right tool for job for example :- one microservice might use relational database to store data while another uses a document database, one microservice might be written in functional programming language while another might use object oriented approach. of course there are still benefits to use standardize approaches where possible but there is no hard requirements. individual microservices team have the freedom to use the most appropriate technology.

  • Individual Deployment :- When we create microservices they are loose coupled that means that we can deploy them individually and this is a huge benefit since there is a much lower risk than upgrading everything in the entire system in one go. And it also helps us to achieve zero downtime deployments, and that's because while we are upgrading an individual microservice it's quit possible for rest of the system to carry on running. Microservice architecture enables team to deploy with much greater frequency rather than waiting months between upgrades which is often common between monoliths changes to microservices can be pushed to production as soon as they are ready and it is even possible to deploy microservices multiple times a day.

  • Scaling :- Microservices give us much more control over scalability, we can scale out each microservice individually which is much more cost-effective than scaling a monolith.

  • Agility :- Microservices make us more agile we can adapt more rapidly to change business requirements by keeping our microservices lightweight and decoupled and more easily reuse scenarios.

Downside of Microservices

Hey, you have seen the benefits of Microservices but nobody is totally perfect right? there must be something always missing on someone. So microservices also has some downsides let's discuss them also.

Microservices solve some problems, but bring new challenges.

While reading the benefits of microservices you may think of well OK if microservices are so great why don't we use it for everything🤔? ~ well it's not a free lunch there is something that can be more challenging with a microservices architecture. So in order to understand weather microservices is right fit for your application or not you must know the downside of microservices.

image.png

Developers productivity :- How can you ensure developers are productive working on the system? do thhey need to download the code for every single microservice and run it individually and configure them to talk to each other that could be very error prone and time consuming. You also need to have a way of working that enables developers to easily work on an individual microservice in an isolated environment as well as testing of microservice in the context of whole application.

Complex Interaction :- If we break an application up into dozens of microservices then it will be very complex to setup interactions between those microservices, which makes hard to understand the behavior of system as a whole. It can also lead to performance issues, if you don't take care you can find that the single operation requires lots of inefficient robust communications between many microservices.

Deployment :- Well deploying an individual microservice is a smaller and safer task than deploying a monolith, when you have many microservices automating deployment becomes critical because you are going to have many more deployments to do.

Monitoring :- If there is a problem in production we don't want to have to connect individually to every single microservice and examine it's logs to and find out which one is the cause of our trouble. So it is essential to have a great monitoring solution to view logs of all of your microservice in a centralized place.

The good news is there are lots of tools and practice available to overcome these challenges and help you succeed with microservice.

I may be write some blogs on some of them in future. For now that's it Thank You for reading this blog 😊😊

KEEP READING, KEEP UPDATING YOURSELF!

Did you find this article valuable?

Support Gautam Jha by becoming a sponsor. Any amount is appreciated!