What are Microservices ?
What are Microservices?
Microservices refers to the small or tiny services revolving around a business logic that come together to formulate a software application. Microservices could also be understood as the Microsoft Architectural style to build software applications in which a number of tiny services make up the application instead of being present in a single bucket. Before Microservices came into the picture, Monolithic Architecture was used. Monolithic Architecture was a contemporary style of building applications where all the services are concentrated at a single place. For e.g. if we are developing an eCommerce application that provides services like viewing the products, logging in to access the cart, adding the products to the cart, and placing the order for those products. If we are working with Monolithic architecture, all these services would be bundled up within a single block, on the other hand working with microservices, we’ll have a number of services which will be independent of each other but would be finally related to accomplishing the result based upon the business logic.
Microservices Architecture
The tiny services in the Microservices architecture are independent and have a separate code base that could be managed by different teams. The client does not directly interact with these services. Instead of that, there is an API Gateway that acts as an entry point to the client requests. The API gateway is responsible for the interaction between different services. API stands for application programming interface, which accepts the client’s requests and extracts the results from the corresponding service that the client requests. For example, when we open up an eCommerce platform and request a service, say I wish to see the products available on that platform then our request is handled by the API and it carries our request to the product services, which generates the response to the request which is finally delivered to the client.
Monolithic and Microservices Architecture
- Monolithic architecture is a setup used for traditional server-side systems where the focus is on the centralized position where a single application is concentrated. An advantage of the monolithic applications is that they can be faster than microservices apps. This may be due to the fact they do not require to interact via API gateways.
- Another reason for the popularity of monolithic architecture was easy deployment. The monolithic architecture was predominantly used and in fact, still it is used because of its low complexity as the entire application resides within a single block. This architecture involves the HTTP request generated from the client’s machine to hit the application server which is further connected with the database. The results are extracted from the database and a result is generated for the client.
- But monolithic architecture comes with various disadvantages and the most common of them is rigidness. As all the services reside at the same spot, the services are tightly coupled increasing the rigidity of the application. Due to this, modifications to the services become complex.
- The biggest disadvantage of a monolithic application is that you cannot scale a service within the application according to the business logic. This is because all the services are dependent and change into a single service will bring down the whole application.
- On the other hand, Microservices works on the concept of segregation of different services in different bodies. This way the different services work independently making the architecture to be loosely coupled.
- Another important point to note is that the different services in the microservices architecture have their own database. This makes them self-reliant, agile, and flexible.
Also, it is possible, that while service is down and undergoing progression the entire application does not rupture and the remaining services can still work.
- Microservices also involves various disadvantages and the most common among them is high complexity. As the application is huge and broken into different domains it becomes difficult to manage the application as a whole.
- Also maintaining consistency and synchronization, sometimes become a challenge in a microservices architecture.
- Both monolithic and microservices architectures come with their own set of advantages and disadvantages. Also, microservices architecture is widely growing over the years. But, both of them coexist and it entirely depends upon the structure of the application that which one to choose for the efficiency of the product.
Features of Microservices Architecture
- Simplicity
The microservices are small focused. This means they can be easily managed by the development team without any extra efforts. Moreover, as the code is not clustered similar to the monolithic architecture, so bug fixing is quite easier.
- Loosely Coupled
Microservices architecture is loosely coupled in a way that the services are not tightly packed i.e. they are independent of each other. If I need to update a particular service, so there is no need to deploy the entire code and instead, we can just update that particular service.
- Fault Isolation
As the services are independent, the fault in an individual service won’t bring down the entire application. For example, if the card service in an application is not working that does not mean it will bring down the entire application just like the monolithic architecture. This feature of microservices architecture proves to be of great significance.
Docker and Docker Container
Whenever we talk about docker, we refer to the entire ecosystem of docker products which includes Docker client, Docker server, Docker machine, Docker hub, etc. Docker client is a tool to which we give commands for reaching out to the docker server in order to generate the desired results. The Docker server is a server running in the host operating system which is responsible for running containers. Now the point is, why we need docker? Understanding dockers, we’ll realize that docker plays a vital role in software development and solve problems that may be of great significance. For example, a development team build software and gave it for testing. After the testing was successful, the software could be deployed. Now the thing is, as a developer we need a framework to build the application, if we are developing the application in Python we require the Django framework or if we are working with Java we need the Spring framework. While developing an application, we require a framework along with some libraries and dependencies so before starting the application, we need to download the libraries and dependencies. Now when the application is complete we’ll send it for testing, when the testing team starts working on the project it is quite obvious if the team faces certain issues. This may be due to the dependencies, although the testing team may also download the entire list of dependencies there may occur the difference between the versions of dependencies among the two teams which arises issues. It may happen that the same application working on the developer’s machine may not work in some other machine. To get rid of these issues, we can install docker on the system, and on this docker, we can have multiple containers and each container can run its own application. Now when we have built the application, we have to pack the container to pack the application. When the container is packed, an image will be created and this image goes to the tester and they can create multiple instances and we can call them multiple containers. The image can be thought of as a class and containers as the objects of a class. This way a number of issues would be solved because now there is no need for the multiple dependencies and only we need docker installed on the system and we create the container with multiple libraries and then the containers could be shipped between different teams.