Microservices and Monolithic Architecture - Resilience Engineering
Saurav Prateek
Engineer @ Google | Ex-SWE @ GeeksForGeeks | Authoring engineering newsletter with 30K+ Subs | 50K+ Linkedin | Content Creator | Mentor
Introduction
Systems are becoming large and complex with time. Now a single system or an application is responsible for performing multiple functions, providing users with multiple features and services. Such a large system can get complex sometimes as they have multiple components functioning altogether. Hence, writing modular codes at the backend will not be enough to ensure a structured design. Apart from that, the system should also be structured at a higher level. There are multiple ways to keep your system structured so that it can be easy to maintain and understand.
A System having multiple components can keep all their components at a single machine or at a single place and such an architecture is known as a Monolithic Architecture. While there can be other cases where systems may store their different components individually at different systems all of them connected through network calls, such an architecture is known as a Microservice Architecture. We will be discussing both the architectures in detail, looking into their advantages and disadvantages. Let’s take an example to discuss both the architectures in order to get a crystal clear understanding of these concepts.
Suppose we are designing an E-commerce Application having multiple components. Let’s see what are some expected characteristics when we design it through a monolithic architecture and via microservices.
Monolithic Architecture
A system implementing Monolithic Architecture stores all of its components at a single place or tightly coupled and highly interdependent on each other. Suppose we are designing an E-commerce Application which has multiple components like : Product Catalogue, User Profile, User Cart and many more components.
Being a Monolithic Architecture the system stores all its components at a single machine. Such a system can have following characteristics :
Microservice Architecture
A system implementing Microservice Architecture has multiple components known as microservice which are loosely coupled and functioning independently. Suppose we have an E-commerce Application having multiple components as discussed earlier. In a microservice architecture all these components are deployed on separate machines or servers which communicate remotely with each other through a Network Call or a Remote Procedure Call (RPC). These components function individually and solely as a separate entity. They come up together to form an entire system.
Basically a large system is broken down into multiple components which are then deployed on distinct machines and are set to operate independently from each other. All these components function as an independent and complete system.
A Microservice Architecture can have following characteristics :
领英推荐
Technology Heterogeneity
In a microservice architecture, we have multiple services working independently. In these architectures, we can use different technologies in different services. This also helps to pick a more suitable and correct tech stack for each service.
Along with different tech stacks, we can also change the way we store the data for different services. We can store data according to our data needs in different microservices. For Example: For a social network we might store the users’ interaction in a Graph-oriented database to reflect the highly interconnected nature of a social graph. But perhaps for the posts that users upload over the service, we can store them in a simple Document-oriented data store. This gives rise to a Heterogeneous Architecture.
With microservice architecture, we can also adopt new technologies more quickly. One of the biggest barriers in trying out new technologies in a monolithic architecture is the high risk associated with it. With a Monolithic Architecture, if we want to try a new Programming Language, Database or a Framework this will impact a huge percentage of the system.
But with the systems having a Microservice Architecture, we have a lot of independent services where we can try out a new piece of technology and may also experiment with it. We can pick a service with perhaps the lowest risk and use the technology there knowing that failing to adopt will have the lowest negative impact on the system.
Resilience Engineering
In a Microservice Architecture, if one component/service fails then it doesn’t impact the entire system. Rest of the other services can still function well while that one service is down. But in a Monolithic Architecture, if the service fails then everything may stop working. Hence generally with a Monolithic Architecture, we run services on multiple machines to reduce the chance of a Single Point of Failure.
But in order to ensure that our Microservice Architecture embraces the improved resilience, we need to understand the new source of failure that Distributed systems have to frequently deal with. Yes, these are Network Failures. Since in a microservice architecture, we have multiple services working independently, these services generally communicate with each other through RPC calls. These RPC/Network calls might fail sometimes and in that case we should know how to handle this and what impact (if any) it should have on the end user of our services.
Concluding
We had a basic discussion on both Monolithic and Microservice architectures. But we can’t assume that every time a Microservice Architecture can be a valid solution. It depends upon the system we are designing and its needs. Many times when there is a small team working on a system, a Monolithic Architecture is preferred. And they can also be scaled horizontally by adding more and more servers, where each server handles every part of the service. Both the architectures have their own advantages and drawbacks.
I feel this edition would have brought some clarity towards the concept of a Microservice and a Monolithic Architecture, especially to the beginners. I will come up with more content like this on System Design and Distributed Systems.
Meanwhile what you all can do is to Like and Share this edition among your peers and also subscribe to this Newsletter so that you all can get notified when I come up with more content in future. Share this Newsletter with anyone who might be benefitted from this content.
Until next time, Dive Deep and Keep Learning!
What a great piece?of writing!
Senior Software Engineer at Checkout.com
2 年Saurav Prateek always a pleasure to read you. Nice article. I want to add that you have Modular Monolith applications within the set of Monolithic applications. Those applications shouldn't be difficult to understand, and depending on how you code them, their components are not necessarily tightly coupled. Another point would be using different technologies in Microservices, especially different programming languages. That might sound great at first glance, but you could have trouble finding developers for one specific programming language or depending on one person who is the only one in the company capable of working on a particular microservices because of the programming language. Besides, it would be nice to show all the disadvantages that come with Microservices architecture. You know that a distributed system can get complex as well. To build a Microservices architecture, you need more knowledge than to build a Monolith. Debugging it can be quite hard, you need some distributed tracing, observability tools etc. A message for developers: If you don't know how to build a Modular Monolith, don't build Microservices because you may end up with a Distributed Monolith.
Senior Software Engineer @ Meta
2 年Another hit as always!
Fullstack developer | Nextjs | Nodejs
2 年Great stuff!