In this tutorial we shall understand about what a micro architecture is and how it is useful in designing a highly scalable system.
So before learning about Micro Architecture, we shall first understand why Micro Architecture came into existence and how it is useful for the companies.
Before the introduction of Micro Architecture, there was a Monolithic Architecture.
A Monolithic Architecture is like a big box where all the software components are assembled in a tightly packed manner.
It means that all the components of a Monolithic Architecture are interconnected and inter dependent.
For example:
If you visit an online shopping website, they will be having:
1. Products service, where customers can look at the product.
2. Customer service, where customers can seek help to resolve any issues.
3. Cart service, where customers can buy the product.
So when you deploy the application, it will be deployed as a single instance that will be running all the time.
For scaling them, we shall run multiple instaces of these application and keep them behind the load balancer.
The only advantage of these kind of application is the deployment will be easy and while scaling the application, you need to run multiple instances of the application which is easy.
But there are many disadvantages for this kind of architecture. Some of them are as below:
1. When you have a very large application, it will become difficult to modify and deploy the application without knowing all the dependancies.
2. The development and maintanance of the application will be difficult. As the application size is large, a simple bug fix will require complete analysis of the application.
3. The application memory consumption will be unfair. For example, a chat application will require less amount of CPU usage, but a payment checkout will require quick and immediate CPU resource. But in these kind of application, we cannot divide the CPU resources.
4. Single point of failure. Because all of the application are tightly dependent, if one of the application goes down, entire application will be effected. Hence it will make the application highly unstable.
5. Since all the modules are interdependent, adding new module or adding a new feature for existing module will become difficult.
Hence we shifted towards Microservice Architecture.
What is a Microservice Architecture?
This architecture is a collection of small autonomous services that together form a complete application.
Here all applications are independent of each other. They communicate through API provided by the applications.
Below are some of the advantages of using Microservice Architecture:
1. Each microservice can focus on one business logic
2. If any one of the service is down, it will not affect other services, as they are independent of each other.
3. Developement and bug fixing is easy, because the developer will focus on only one module.
4. Instead of having a single database, each microservice will be having its own database, avoiding single point of failure.
Below are some of the features of MicroServices:
1. Decoupling: The modules can be easily build, scaled and deployed.
2. Autonomy: Teams can work independently
3. Continious Delivery
If we take the same example of online shopping application, we have
1. Products Microservice.
2. Customer Microservice.
3. Cart Microservice.
As we have made all the modules as microservice, each module will ocmmunicate with the API provided by other application.
Components involved in Microservice Architecture:
1. API gateway
2. Load Balancer
3. Database
4. Service discovery
Open-source tools for developing Micro-services:
Operating System: CentOS
Container: Docker
Scheduler: Kubernates
Monitoring: Prometheus
Messaging: rabbitMQ
API: POSTMAN
Programming Language: Elixir
Below are some of the companies using Microserviecs:
Twitter
Netflix
Amazon
Paypal