For many years now
we have been building systems and getting better at it. Several technologies,
architectural patterns, and best practices have emerged over those years.
Microservices is one of those architectural patterns which has emerged from the
world of domain-driven design, continuous delivery, platform and infrastructure
automation, scalable systems, polyglot programming, and persistence.
What is Microservices?
It is an architectural style which is autonomous, independently deployable services
collaborate together to form an application.
They should be
optimally small, but there is no official size limit. Many teams try to keep it
as small as possible(like 100 lines of code), but the benefits of microservices
still apply even if the application is a bit large.
Monolith: It is a software application that has
all of its code in a single codebase. The build artifact is generally a single
process that runs on a single server or machine and keeps all of its data in a
single database.
The development of an environment for monolith typically uses a single consistent technology such as what
programming language or SDK you use.
Benefits of Monolith architecture:
Simplicity: One codebase. Easy
to find things.
Deployment: One
application to replace.
Disadvantage: It is difficult to scale. It is
generally meant for small teams. If the project grows larger than the
difficulty arises in maintaining the application. Even if you have modularized
your application well, these modules will get too entangled that it becomes
difficult to update the app easily.
A single line change
requires an entire application to be redeployed, which causes additional
regression and it's risky. This also requires a lot of downtimes.
Horizontal scaling
often not possible and hence you have to go for vertical scaling(to install
costly and powerful servers). Also, the whole application has to be scaled together
instead of a single component.
It’s a legacy
technology. The whole codebase has to be updated to include any new technology.
This reduces agility.
Distributed Monoliths
Even if your
services which are separated different components and are interacting over the
internet, it is still not a microservice, as it is accessing a single shared
database and they are all tightly coupled to each other such a way that you
have to deploy them all together. Any new changes often require changes to
multiple components.
Benefits of microservices
- As Microservices are separated into smaller pieces each piece can be owned and maintained by a separate team. In this way, a microservice is easier to understand. for sizing microservice should be small enough so that it can easily be rewritten and the old code can be thrown away.
- Microservices allow us the Flexibility to use new technologies without the need to upgrade the complete system in a single go. This also allows us to use the right tool for our needs. Eg. One microservice can use a relational database while the other can use a document database.
- Since they are loosely coupled they can be deployed independently. This causes low downtime and high-frequency deployment. The risk of breaking the complete application is low because of loose coupling.
- This is cost-effective and easily scalable.
- Easy to adapt to change of technology or design. Also, they are reusable.
Disadvantages of microservices
Along with many
advantages of microservices there comes some disadvantages too. so before
deciding that the microservice architecture is a good fit, you should be aware
about some of the challenges which microservices bring along.
- Developer Productivity
Developer
productivity is a major concern when working with microservices as you have to think about how the developers will work with different components of the
service. Do they have to download the complete service and configure each and
every project? Along with this testing
of the microservices also has to be managed in context with the whole
application as well as individually.
- Complex Interactions
The
communication between different microservices
also needs to be managed as we do not want the communication between
different services to be over-complex and time-consuming.
- Deployment
Deploying
individual microservice is easier and safer when compared to deploying a
monolithic application but this process gets complicated when it comes to many
microservices. In this scenario, the process has to be automated so that the chances of error should be less.
- Monitoring
Monitoring
and logging has to be proper for microservices because in case of an error we do
not want to debug and check the logs for each and every individual microservice
and hence a centralized logging system has to be defined.
So this is all about a basic introduction to microservices to get a basic idea about it.
In the next post, I will come with a live example of the same.
No comments:
Post a Comment