We live in a world that’s constantly growing. There are new applications and services that come up everyday. Existing ones evolve to constantly meet the demands of today’s world and to keep up with the latest trends in technology. This essentially means that there is hardly any time devoted to the maintenance of such applications and services. Nobody likes down-times. If a service is down for sometime, its users would naturally start looking for alternatives, and with such a huge network of service providers available over the internet, they would quite obviously even find one. This is where Microservices comes into the picture.
This blog delves into the “What” and “Why” of Microservices in detail.
If you are not very new to the world of The Cloud or Systems, then you would’ve heard the term “Microservices” quite frequently. Microservices, as the name suggests, is an architectural style that branches out an application into several small independent applications or services. These individual modules are independently built and deployed. Going by the official definition,
Microservices - also known as the microservice architecture - is an architectural style that structures an application as a collection of services that are - Highly maintainable and testable - Loosely coupled - Independently deployable - Organized around business capabilities - Owned by a small team
The microservice architecture enables rapid, frequent and reliable delivery of large, complex applications.
Let’s go through each of these points one by one.
Now that we know what Microservices are, we need to know why they are required in today’s world. But for that, we first need to know what monoliths are.
In software engineering, a monolithic application describes a single-tiered software application in which the user interface and data access code are combined into a single program from a single platform. In simple words, it’s an architectural style that does not treat modules independently in an application. The application is deployed as a whole, and all the different components of an application use the same dependencies, etc. It contains a single executable that performs all of the server-side functions for an application. Let me explain with the help of an example.
Let’s consider an e-commerce application. It can have several components to it - a catalogue of products, an ordering system, a payment system, etc. This would mean there are three different containers, one for each service, deployed independently under the Microservices Architecture. Using the Monolithic Architecture, we would need only one container to bundle up the entire application for deployment.
We’ve read in detail about what microservices and monoliths are. But why are microservices preferred over monoliths?
Let’s consider a monolithic application with a huge codebase. A small bug somewhere brings the entire application down. It would naturally be difficult to pin-point the location of the bug because of the huge codebase. It also does not make sense to bring the entire application down because of the bug, when the rest of the application is working completely fine. Issues may also arise when scaling up or scaling down the application. All components of the application would have to use the same versions of dependencies. Any conflicts with dependencies can break the entire application.
Now let’s consider the same scenario with Microservices. A small bug in the codebase need not bring the entire application down, since each component is independently deployed. This also means that bugs are easier to trace and fix. Scaling up and scaling down the application is much easier as each component is bundled together with its dependencies and containerised for deployment.
Although microservices have an edge over traditional monoliths due to the aforementioned reasons, it does come with several drawbacks. As each component is deployed independently and communication between components happens only via APIs, there’s the problem of consistency. It also uses up a lot of resources, as there are multiple deployments, and not just one.
However, the reason microservices are preferred over traditional monoliths is because of its ability to cleverly deal with bugs, and ease of maintenance. It may take up a lot of resources, but with cloud providers like Google Cloud, AWS, MS Azure providing resources at a nominal price, it is a welcome trade-off. After all, nobody likes down-times, and hence, microservices are the way to go.