Difference Between Monolithic and Microservices based Architecture

Sarath Pillai's picture
Monolithic VS Microservices

Microservices based architecture has got a lot of media traction during the last few years. Plenty of blogs and articles have already been written about the benefits of microservices based architecture. Its nothing but a unique way of designing applications as different small components, which can be independently deployed as individual services.
 

In short, microservice architecture is nothing but an approach to application development, where an application is dissected to different components, and each application components are developed individually,packaged individually, and deployed individually, in individual processes.
 

These services can often communicate with each other using mechanisms like HTTP REST APIs. These different components are often developed by individual teams, and are deployed separately by often different mechanisms. Most of the times, these different services are written in different programming languages. To understand microservices based architecture, one should first go through the more adopted and standard monolithic architecture of application development.

 

Monolithic applications are built as a single package, that has all required components are services included.

 

Mostly a web application has two primary components.

  • A Relational Database.
  • A Server Side Application.

The Server side application here will do the heavy lifting of whatever operations that happens. The Server side application will take care of handling the HTTP requests from the clients, Retrieving data from database, Update database with new data, Giving proper HTML response to the clients.


Monolithic Application

This is the traditional way of building web applications. Here all the business logic for servicing a user request is packaged into a single application process(which will typically be running in an application server platform). All different features of the application is written as separate modules and classes and will ultimately be packaged into a single large application. For example, if the application is made in Java, then the all the components is packaged into a war file and is deployed to a tomcat, jboss or a jetty server.  If the application is built in Python Django or Rails then the same is deployed as an entire application directory structure.

 

Scaling monolithic application is as simple as creating multiple instances of the application and placing all of them behind a load balancer.

But there are caveats to this approach of monolithic application architecture. Some of them are mentioned below.

  1. Sometimes the application package itself becomes bigger and bigger, after so many iterations of adding features etc, it can really become huge. Once the application itself becomes big, quick development and delivery becomes too much difficult. Bug tracking and fixing also becomes too much difficult to handle. Also simply imagine the time a large application will take to fully start(as it will be expanding so many libraries and features from the package.).
  2. Continues deployment will suffer a lot. This is because, let's say you want to deploy a bug fix in one of the component in the application. Now as the application is monolithic, the entire application needs to be re-deployed (which contains the minor bug fix in one of the component..)
  3. Another sad disadvantage is scaling. To scale, you need to scale the entire monolithic application, even though you only need more resources on one of the component of the big application. Basically selection of server resources and sizing will always depend upon the highest resource intensive component in the big application(although the other components does not need much resources)
  4. Adopting new technologies or languages will be difficult. As you cannot implement one language for one module of the application easily(although this can be done).

 

Now let's see how microservices based architecture tackles all of these. In Microservices based architecture, a big application is built into smaller components and these components can talk to each other when required. These different smaller components can be called as interconnected services.

 

The main advantage of microservice based architecture is that, different components can be deployed independently, without re-deploying the entire application again for a small change. Many e-commerce and other high trafficked application companies are using microservices based architecure.

Microservices

 

As shown in the above diagram, the front end is completely separated from the core logic and can be scaled independently. Also the backend components are separated to different services, with individual databases. Having individual databases for each of the service can help in modifying database schemas without impacting any other component in the infrastructure. 

Each service shown above can be placed behind their own load balancers, to achieve more throughput and availability of that service.

Another main advantage of using services is that each service can use their own required database types. Some services can use nosql databases if required, some can use the traditional RDB.

 

The name microservices is a bit focused on the size of the service. Unfortunately micro does not say how much is considered as micro(well in application development we can think and calculate this as lines of code). This can be different for different companies. A good method is to keep individual services being administered and developed by a team of 10 members or similar. 

The main advantage here is to let smaller teams manage different services here. Also the individual teams can now have the complete authority for selecting required technology stack that works best for their service. The only thing that the team needs to ensue is the interface exposed by the service must satisfy the requirement of other intercommunicating services.

 

As each service can be deployed individually, continues deployment is possible, without impacting other components of the architecture. Also each service can be scaled individually, which makes deploying the required number of instances which satisfies a particular service requirement easy. Also you can select the best suited hardware for a particular service.

 

Let's say you have a service for transcoding videos to different formats(which is a cpu intensive process), here you can use a higher CPU hardware, only for this service(other services can use a less CPU hardware). In monolithic you have to select a hardware that satisfies all other services that are part of the giant application(which is not efficient use of resources).

 

Monolithic ArchitectureMicroservices based Architecture
Gets bigger and bigger over iterations, and becomes difficult to manage and takes really long to startup, if the application is too big.The size will remain substantially smaller, as each component is dissected to smaller services.
Continues deployment becomes difficult, as a small change to a component in the application, requires redeployment of the entire application.Continues deployment is possible here, as each service can be deployed independent of each other.
Scaling of application requires entire application scaling(ie: to launch multiple instances of the big monolithic application to serve the need), even though only one small part of the application is resource intensive.Scaling of individual component is possible here, as each different component is de-coupled to different services, and can be scaled up horizontally and individually.

 

Microservice based design is actually not a new thing. In fact the UNIX design philosophy is exactly the same. Although there are many advantages of using microservice based architecture, its not a solution to all your application development and deployment issues.

 

Some of the smaller issues or I must say drawbacks in migrating to microservice based architecture are mentioned below.

 

  • In a monolithic application, components can talk and deal with each other by simply using language internal procedures or calling a particular method(as everything is part of single application). In the case of microservice based architecture, developers will have to deal with logic for intercommunication between services, and also deal with failures between them. Although its not a big deal, it still is bit more complex, compared to monolithic applications.
  • Testing a service is a bit more tedious compared to monolithic application, because one service might depend on other service as well.
  • There needs to be a service discovery mechanism, that will help services to find other service. This is necessary, because in a microservice architecture, service instances are mostly immutable. Also the location(the ip address) of the service will change dynamically(during scale up, scale down, or new deployment etc), and others needs to get the new location without delay. 

 

So as a footnote, to conclude this article..

Monolithic is suited if the application itself is really small, and does not have much logic and modules in it. Microservice based architecture is best suited, if your application is really big, complex, and does a lot of different things.

 

Rate this article: 
Average: 4.1 (74 votes)

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.