Before microservices all components of software were part of a single unit. If the different teams are working on different components then they have to make sure that they should not affect each other work. In monolithic e-commerce websites, user interfaces, payment options, product pages, and shopping carts all will be part of a single unit, and we should ensure that changes in one functionality should not affect other functionality. If a developer changes to code for payment functionality we need to build the whole application and deploy it again as a single package.
Why Microservices :
In monolithic architecture, applications can become too large and complex and eventually, it will become hard to track the application and changes.
If we want to scale a specific service then we need to scale the entire application which also leads to inefficiency.
Testing, deploying, and maintaining the application will become tedious and will take a longer time, this is something that neither the developer nor the organisation wants.
And it is no doubt that a bug in one module can bring down the entire application.
So the answer to all of this is microservices; Now what are microservices?
What are Microservices :
"In software engineering, a microservice architecture is a variant of the service-oriented architecture structural style. It is an architectural pattern that arranges an application as a collection of loosely coupled, fine-grained services, communicating through lightweight protocols"
This definition is available on Google, so let's understand this properly;
In Microservices we break down the application into multiple smaller applications, this breakdown can be done based on business functionalities. E-commerce websites, for example, can be divided into sections based on product, checkout, shopping cart, user account, and so on.
In the end, each micro application should do one specific job, and each microservice should be self-contained and independent from each other, this is called loose coupling. This means each microservice needs to be developed, deploy and scale independently. So if we change something in payment service then we only need to build and deploy payment service. So each service will have its own version and dependencies.
Now question arises If each microservices are isolated then how do they communicate with each other.
How Microservices Communicate :
It is obvious that the payment service will need something to communicate with the checkout service and the checkout service will need something from cart service. So how they will communicate?
Synchronous Communication: In this they can communicate with the help of API calls, So each service will have an API endpoint from which they can communicate with each other by sending requests to the API endpoint.
Asynchronous Communication: In this service will send a message to an intermediate message service or broker and then the message broker will forward that message to other services.
- Service Mesh : Service mesh works by adding a sidecar proxy to each microservice in the system. The sidecar is responsible for intercepting all traffic to and from the microservice and forwarding it to other microservices in the system, as well as applying policies defined by the service mesh to manage the traffic. This is something kind of adding helper service which take care of communication logics, so we have not to code this logic in microservices. Service mesh itself is a great topic which we will discuss in upcoming blogs (For now you can Checkout this Video).
So now we know why, what, and how about microservices. Lets now look into the problem arises due to microservices :
Challenges with Microservices :
One of the main challenges is configuring the communication part between services. Lets say one service is down and another service is sending a request to that service accepting the result, In this case an unknown error can occur.
Many companies deploy microservices multiple times a day, Large companies like Google, Amazon ,Microsoft have 1000 of microservice, So in this can you must know how to configure the microservices and its release process, which can be a challenging task.
Monitoring of the microservices is also a difficult part, it will be hard to determine which microservice is down, when it is down and why. So we need proper setup to configure the application and also for monitoring of application.
No Worries, to solve these challenges CNCF and the Open source community is here to help you, There are various tool available to monitor, secure, manage and deploy your microservice.
We will go over each tool in detail in future articles for Now, Thanks for Reading, and Sayōnara.