Which architecture should you use: microservices or monolithic?

Which architecture should you use: microservices or monolithic?

·

4 min read

There is a widespread saying that if you fail to plan, you plan to fail; This adage is also quite true during software development. Before you start writing code, it's a good idea to establish a system architecture that will make implementation, scalability, and maintenance easier.

“…A great architecture alone isn’t enough to guarantee your software will be a smashing success, but the wrong architecture almost guarantees failure. …”
-Michael Keeling

This article will look in-depth at what monolithic architecture is, why there is a clear need for microservice design, and why both architectures are still highly viable.

Monolithic architecture

This architecture, which is not obsolete, is regarded as a conventional method of building applications as discrete and indivisible units. As the name suggests, the entire function, database, and business logic are tightly coupled.

Example of a monolithic application

1-V2.jpg

Consider the graphic above to be an online travel application that allows visitors to purchase an airline ticket as well as a hotel reservation. This application comprises various components like the user interface for the traveler to interact with, the backend services that consist of authorization, flight booking, hotel booking, payment, and a single database.
Although each module is unique, they are developed and deployed as a single application. Everything resides within the instance of that server thereby causing all the services to be tightly coupled.

This approach has certain advantages as well as disadvantages.

Advantages of monolith architecture

  1. Easy to build.
  2. Low complexity involved as managing is simple.
  3. performing end-to-end testing is done with ease
  4. Code can be easily shared across modules thereby reducing code duplication.
  5. Easy to deploy
  6. Scaling can be easily done horizontally by running multiple server instances behind a load balancer.
  7. Less security and network latency concerns when compared to microservice architecture.

Drawbacks of monolith architecture

  1. It usually has a large codebase that makes it harder for developers and quality assurance professionals to understand the code and business knowledge.
  2. Making a change to the existing codebase can be difficult and affect other code parts.
  3. Scaling a service based on a specific business process is not possible; instead, the entire application is scaled.
  4. The application is fragile because it has a single point of failure. A bug might cause downtime on the entire application.

Microservice architecture

Microservices architecture is a design paradigm in which a single big application is made up of multiple smaller services that are loosely coupled and may be developed and deployed independently. Each service is capable of:

  • focusing on solving specific problems based on the business requirement
  • communicating with each other over the HTTP resource API, event streaming, or message brokers.
  • having their specific technology stack and database or shared database across different services.

3-V2.jpg In contrast to the monolith approach in building an online travel application, each service is independent of the other but can also communicate.

It is difficult to contact each microservice using its unique protocol configuration in a client application. Therefore an API gateway, which serves as a single entry point into the multiple services, is largely responsible for receiving client requests and forwarding them to the appropriate microservices. The protocol translation which is provided by the microservices API gateway ensures that each microservice gets requests using the appropriate protocol.

Advantages

  1. Introducing a feature or refactoring the codebase can easily be done without affecting the entire application.
  2. If proper monitoring is done, it is easier to identify performance issues and reduce downtime.
  3. The application is not restricted to a particular technology/framework as a mixed stack can be used to solve certain business purposes.
  4. Loosely coupling allows for independent deployment and granular scaling i.e each service can be scaled independently
  5. Instead of learning and mastering the complete system, a new developer onboarded to the team may quickly grasp and master a specific microservice.

The majority of the disadvantages of the microservices approach stem from its complexity. Let us look at a few of them:

Drawbacks of microservice architecture

  1. Performing testing is difficult due to the multitude of independent modules.
  2. Microservice approach can be less secured as communication is done over the network and not in memory.
  3. Managing multiple services can be difficult.
  4. The operational cost of designing a microservice architecture is substantially higher when compared to a monolithic application.

When is a monolithic architecture appropriate?

This approach is used when :

  • Building a small-sized application.
  • Creating an MVP. At this stage, your aim is to get feedback from first users as fast as possible, and monolith applications are the easiest option to do so.

When is a microservice architecture appropriate?

The lack of system downtime during maintenance and upgrades is a big pull for larger companies looking towards efficiency over simplicity - Kofi group

A microservice architecture can be adopted when:

  • building a large-scale solution.
  • you intend to increase the size of your development team and scalability is crucial for your project.

Conclusion

You should not begin a new project utilizing microservices unless you are confident that your application will be large enough to justify the investment.

References:

Monolithic vs microservices architecture

Microservices vs. Monolithic: Which Architecture...

Introduction to Monolithic Architecture and MicroServices Architecture