Monolithic vs Microservices Architecture

One of the things that we have been witnessing in the past few years is a transition from monolithic architecture to microservice‑oriented architecture. Microservices architecture is the one which has been successfully adopted by organizations like Netflix, Google, Amazon, and others. Here, we have to know what is Microservice architecture advantages over monolithic?

While developing any web-application, one can start with layered architecture which consists of different layers.

  1. Presentation Layer (consisting of HTML pages and/or JavaScript running in a browser)
  2. Business Layer ( will handle HTTP requests, execute some business specific logic, retrieve and update data from the database )
  3. Database Layer (consisting of many tables usually in a relational database management system)
  4. Integration Layer ( integration with other services (e.g. via messaging or REST API ).

Business Layer can be modularized and can create modular architecture. Consider a typical web application which has modules as shown in an image.

Typical Monolithic Architecture diagram

Monolithic Architecture

Despite having a logically modular architecture, the application is built and deployed as a single logical executable is called Monolithic.

Usually, we’ll have one database that all of these modules in the application will use for storing and retrieving data. In the early stages of the project, it works well and basically most of the big and successful applications which exist today were started as a monolith. When it evolves into a “big ball of mud” a situation where no single developer (or group of developers) understands the entirety of the application.

Benefits of Monolithic architecture

  • Easy to develop.
  • Easy to Test. (We can test end to end flow by simply launching the application)
  • Easy to build and start with smaller codebases.
  • Easy to scale the application horizontally by running multiple instances of application behind the load balancer.

Drawbacks of Monolithic architecture

  • Complex to fully understand and made changes fast and correctly in the large and growing codebase.
  • The size of the application can slow down the start-up time.
  • To make any alterations to the application, a developer must build and deploy an entire application.
  • Impact of a change is usually not very well understood which leads doing extensive manual testing.
  • Bug in any module (e.g. memory leak) can potentially bring down the entire application. Moreover, since all instances of the application are identical, that bug will impact the availability of the entire application.
  • Monolithic applications have a barrier to adopt new technologies. Since changes in frameworks or languages will affect an entire application. which can limit the availability of “the right tool for the job“.
  • Continuous deployment is difficult.
  • Limited re-use is realized across monolithic applications.

Scenario: For example, consider Flipkart big billion days.  Mostly on these days, traffic on product, order and payment module will increase enormously. To support the traffic, we have to scale the whole application horizontally. But scaling entire application is an expensive and more time-consuming process. This scaling includes processing like cloning entire application and deploying to multiple servers. But here we have to keep in mind, we need to deploy specific modules such as product, order and payment modules, not the entire application.

To overcome all above problems, People came up with another alternative solution, which provides a different approach to software development.

Microservice Architecture

The idea is to split your application into a set of independent services that are developed, deployed and maintained separately. Each microservice is a small business oriented application that has its own hexagonal architecture consisting of business logic along with various adapters.

The Microservice architecture pattern significantly impacts the relationship between the application and the database. Instead of sharing a single database schema with other services, each service has its own database schema.

Having a database schema per service is essential if you want to benefit from microservice because it ensures loose coupling. Each of the services has its own database. Moreover, a service can use a type of database that is best suited to its needs, the so-called “polyglot persistence” architecture.

The Microservice architecture pattern corresponds to the Y-axis scaling of the “Scale Cube” model of scalability.

 

Benefits of Microservice architecture

  • Faster to develop, and much easier to understand and maintain.
  • It enables each service to be developed independently by a team that is focused on that service.
  • To make any alterations to the application, a developer needs to build and deploy only that microservice. It will improve build and startup time of application.
  • It reduces the barrier of adopting new technologies since the developers are free to choose whatever technologies make sense for their service. Provides “the right tool for the job”.
  • Enables each service to be scaled independently.
  • Continuous deployment possible for complex applications.
  • Easily discover services as potential reuse candidates.
  • With microservices, if you have a problem, that is isolated in a specific component or service of your architecture. So there will no downtime for an entire application.
  • Faster iterations and decreased downtime can increase revenue. User retention and engagement increases with continuous improvements offered by microservices.

Drawbacks of Microservice architecture

  • Testing a microservices application is also much more complex than in case of the monolithic web application.Usually, if you want to test an app that’s built in a microservice‑oriented architecture, you have to start all of these services at the same time so you can have them talking altogether and can successfully implement an integration test.
  • Inter-process communication between microservices has to implement separately using REST or Messaging Service.
  • Requires complex infrastructure to maintain and monitor the services.

Scenario: For example, consider Flipkart big billion days.  Mostly on these days, traffic on product, order and payment services will increase enormously. To support the traffic, Unlike monolithic architecture, we just need to scale the services such as product, order and payment services.

This process can be automated using some orchestration tools such as Kubernates and docker-swarm. We will discuss containerization and orchestration in next blog.

Share this post