What are Microservices, an Example and Advantages and Disadvantages of Microservices?
Microservices architecture is a pattern for organizing an application into individual services that can scale with demand, It’s an architecture where every application functions as its own small independently deployable services and these services are deployed in containers, and these containers speak with other microservices with the help of APIs.
These individual services or mini applications performs a specific task and communicate through API’s that connect them together and these different microservices function as one component.
Monolithic application combines all the functionalities as tightly coupled modules, which are dependent on each other and run as a single process. In case if something goes wrong with one of these functionalities, the whole application might go down.
Example like an ecommerce platform with different functions. In a monolithic application the different components of the app like billing, shipping, orders, and inventory management are tightly coupled together. If the shipping component is not working, the entire ecommerce platform will be down or will be affected
Also monoliths have a lot of shared libraries, they are highly dependent on each other. In case a library needs to be modified, it might affect the other components and you could potentially bring down the entire application.
So, in a microservices-based deployment, we still the user interface component, also we still have the other components like billing, shipping, orders, management but they are independent services running inside containers. Micro services run in containers which run on a virtual machines, the team responsible for the order management can use the language and framework that they want to use. The team that runs the Inventory Management, can use their own language and their own framework which are currently being used, another benefit is that you’re able to iterate it whenever it is required. The containers and services are deployed with the help of DevOps pipeline. As a developer commits the code it goes through the CI/CD pipeline and automated testing, once all that passes, that code can be deployed into production immediately.
When something goes wrong with any of the “services” or components in a microservice architecture OR if any of the services crash, it will not affect the other services . These individual services are independent and can be deployed individually, meaning your application can start running even if some components are missing. They can also be stopped and removed, without crashing the whole system.
Now let us look at the challenges of Monolithic app so that we can understand the benefits of Microservices
Scaling a monolith app is a challenge
- It has Slower deployment, all components of the app need to be updated at the same time.
- Teams are Stuck with the same language or framework
- Highly Dependent, if one component goes down it affects the other component and the entire application might crash
Advantages of Microservices
- Scalable. Scale the microservice responsible for that (e.g. add more hardware to handle the load). It’s cheaper because you don’t need to scale the entire application.
- Better fault tolerance, When a microservice encounters an error, the other
Microservices will still continue to work, and will not crash the whole application
- Different Microservices can be coded in different programming languages. Messaging services can use NodeJS + NoSQL, PHP for generating reports etc., this ensures efficiency and more performance. This ensures you can adapt to a new language if needed which is not possible in Monolith app.
- Each microservice can be implemented by a smaller team. Since each service is isolated to another and supposed to be performing a specific function, use cases can be narrowed down, thus developing it is easier.
- Easier to understand by newer team members. Since a microservice cover only the minimal part of the application, new developers can easily grasp and participate, and can become more productive quickly.
- Faster deployment. Microservices are small, so they also start faster.
- When something needs to change, only the affected microservices are needed to be modified.
- Reusable. You can reuse a microservice if needed
- You can change your tech stack at will. If determined that your microservice uses the old tech stack and you need to update it, it will not break your other services.
Disadvantages of Microservices
- Dividing the application to individual microservices is a challenge. It requires extensive planning.
- Increased RAM consumption. Since each microservice runs it is own process, it will also require more memory in order to operate efficiently. Good thing microservices can be scaled independently.
- The more microservices being added the more complex your application will become.
- So many Git repos! Each microservice might require its own repository. You will have to pay GitHub or similar hosting services to accommodate multiple private repos for just a single application!
- Dividing the application to individual microservices is a challenge. It requires extensive planning.
- Testing can become complicated and tedious. This can be remedied by automating the tests though.
- Handling use cases that spans different microservices could require communication and cooperation between different teams. This is not much of a bad thing though.
- Dividing the application to individual microservices is a challenge. It requires extensive planning.