Understanding Monolithic Architecture vs. Microservices: A Comparative Overview

ยท

5 min read

Monolithic architecture is like a big, self-contained box where all the components of the application are tightly integrated and packed as a single unit. It's a traditional method where all the functions of the application are managed and operated under a single roof. All the features and functions of the application are included in this big, self-contained box.

Components of a Monolithic Architecture

  1. User Interface (UI)

    • This is what you see and interact with. ๐Ÿ–ฅ๏ธ

    • It's like the buttons, screens, and everything you click or type on.

  2. Business Logic

    • This is the brain of the application. ๐Ÿง 

    • It does all the thinking and processing.

    • For example, it calculates how much your shopping cart should cost, or if you're old enough to sign up for something.

  3. Data Access Layer

    • This part deals with storing and retrieving data. ๐Ÿ—„๏ธ

    • Imagine it as a librarian who knows where all the books (data) are and can get them for you.

  4. Database

    • It's like a big warehouse where all the information is kept. ๐Ÿข

    • For example, your name, address, or what you bought online.

E.g.: Imagine we're building an app like Airbnb, and we're using a Monolithic Architecture. This means everything โ€“ like Authentication, payment system, and listing hotels โ€“ is handled in one big chunk of code. It's like having all the different services bundled together into a single package. So, in this case, all the different parts, such as the sign-in process, payment system, and hotel listings, are combined into one big codebase.

When we're building an app like Airbnb using Monolithic Architecture, it means we develop and deploy the entire Airbnb application as a single unit. This includes using only one CI/CD pipeline. We're also restricted to using only one technology stack. For instance, if the whole codebase is written in Java, we can't write other features in Python. Monolithic Architecture is generally used in projects or startups. It's like putting everything in one basket.

Advantages:

  1. Easy Development, Testing, and Deployment: It's simple and straightforward to build, test, and deploy.

  2. Easier Management: It's easier to manage because everything is in one place.

  3. Rapid Development: You can develop quickly because of its simple structure.

Disadvantages:

  1. Redeployment: If you want to change something, like the authentication feature, you have to redeploy the entire application instead of just updating the part you changed.

  2. Scaling: If you need to scale a specific feature, like the authentication feature, you also need to scale all other functions and services. The same goes for scaling down.

  3. Upgrading: When upgrading a feature, you need to upgrade all the features together. For example, if you want to update the Payment feature to version 2, you also need to update the Authentication and Listing features to version 2. Similarly, if you want to make a change in Authentication, you need to ensure other functions or services are not disturbed.

    Netflix also faced similar issues until 2009. However, after that, Netflix started to follow Microservices. It was the first to adapt Microservices.

What are Microservices?
Microservices are like a well-organized city. Different services are independent yet connected to each other to create a whole functioning system. It's a modern way to design software where each function or service is divided into small pieces but connected internally.

It's like breaking down a big task into smaller, more manageable parts, each of which can operate independently, but together they create a unified and efficient system.

Different services are divided into separate individual units, making the whole application divided into individual pieces. Let's take the example of Airbnb, which has functions or services like Authentication.

Now, developers can independently develop it anywhere, using any tech stack, having different CI/CD pipelines.

It's like breaking down a big task into smaller, more manageable parts, each of which can operate independently, but together they create a unified and efficient system.

When moving from Monolithic architecture to Microservices, the number of microservices depends on:

  1. Business Logic: The organization and division of microservices depend on the business logic. This means that how the business logic is structured determines the number and nature of microservices.

  2. Functionality: Microservices are divided based on the functionality they serve. Each service performs a specific function. The number of microservices is based on how many functions need to be divided and implemented.

  3. Business Requirements: The number of microservices is also influenced by business requirements. Different business needs and goals determine how many microservices are necessary to meet those requirements effectively.

In general, companies that follow Microservices have separate teams to work on each service, such as Authentication, Payment, Listing, etc. Microservices are mostly adopted by big companies like Amazon, Uber, Netflix, etc.

Advantages:

  1. Independent Development, Deployment, and Testing: Each service can be developed, deployed, and tested independently.

  2. Separate Code for Each Service: Each service has its own code, making it easier to manage and update.

  3. High Efficiency: The system operates with high efficiency, thanks to the modular and independent nature of the services.

Disadvantages:

  1. Complexity: Coordinating multiple services can become complex.

  2. Increased Overhead: Managing multiple services can lead to increased overhead.

  3. Network Latency: Communication between services can introduce network latency.

How Do Microservices Communicate With Each Other?

1) API Calls End to End (Synchronous Communication):

Microservices communicate directly with each other through HTTP requests. When one microservice needs to talk to another, it does so by making an API call over the network.

2) Using Message Brokers (Asynchronous Communication):

Microservices communicate indirectly through a message broker, which acts as an intermediary. Instead of directly calling one another, microservices publish events or messages to the broker, and other microservices subscribe to these events.

Message Brokers: Platforms like RabbitMQ or Apache Kafka handle this communication by storing, managing, and delivering messages between microservices.

3) Using Service Mesh:

Microservices communicate through a dedicated infrastructure layer called a service mesh. It manages communication between microservices, handling service discovery, load balancing, encryption, etc.

Service Mesh: Platforms like Istio provide a service mesh. It helps manage and secure the flow of traffic between microservices in a more efficient and controlled way.

Follow Me on Linkedin: https://www.linkedin.com/in/bhavesh-nandave-3aa4a51ba/
Follow Me on Twitter:https://twitter.com/Bhavesh_Nandave

ย