Migrate a Monolithic Application to Microservices

Monolithic Architecture

Monolithic applications are big fat complex single applications that have high complexity. Besides, they are hard to maintain and not easily deployable as well. Failure in one part can bring the whole system down. higher database complexity, improper resource utilization, etc.

To give you a better idea of what monolithic architecture is, here are some of its characteristics:

  • They are a really large single application that serves all the types of browsers, mobile applications, or any 3rd party integrations.
  • They are very complex and have huge structures and files.
  • Monolithic apps are very hard to maintain. (In terms of coding standards, bug fixing, etc).
  • Continued Development will be difficult as large applications cannot deploy very frequently. (Due to the fear of failure, deployment can be time-consuming, you should have to interrupt background jobs before deployment so it will increase the risk factor which leads to fear of deploying frequently).
  • Scaling applications can be difficult. For example, if there is a single application that is doing all the tasks, there might be a chance that some modules need more CPU consumption, some need higher RAM and some need higher graphics or higher I/O operation. When we provide the application higher ram or CPU it doesn’t mean that the module that really needed is consuming that resource.
  • Horizontal scaling is very hard.
  • Development teams usually find scaling monolithic apps difficult. Once an application gets over a certain size, it is really hard to maintain by a single team and then have to divide a team module wise and interference of modules to each other leads to a developer having a broad understanding that will become time-consuming and also affect the productivity of newly introduced developers.
  • Technology becomes a bottleneck. Once an application started development in specific technology then needs to stick with that technology though it becomes outdated.
  • Overloaded IDE due to the large application which will take too much time to open the application and build it or deploy it. So, the developer needs to spend a lot of time on this.
  • Large applications take a longer time to start up which will have an impact on deployment as well as affect the productivity of the developer.


Application load process


The above image illustrates the typical architecture of a monolithic application, where a single application contains all the services which are responsible to do all the tasks.

What is Microservice?

microservice is an architectural concept. It is a distinctive method of developing software systems that try to focus on modules and divide the whole system into fragments in a way that each module becomes an independent service. In simple words, it involves dividing a single huge system that is hard to maintain into smaller services that are independent and highly maintainable.

The Following are the main characteristics of microservices:

  • Each Service should be loosely coupled.
  • Each Service should be highly maintainable and scalable.
  • Each Service should be independently deployable.
  • Each service has specific responsibility based on business capabilities.
  • Each service should be owned by a small team.

For example, looking at the below image, one can easily identify that there are different types of services that have their own databases.

Microservices with their own databases


Here, systems have been divided into a number of microservices which are working without interfering with each other. This is the beauty of the microservices architecture, where each service is one small module which can be worked with minimum interference with other microservice and each service has its own responsibility and can be deployed individually and can be owned by a small team.

Migrating Legacy Application To Microservices

Strangling the monolithic application

There are mainly two approaches for migrating monolithic apps into microservices.

  • Implement new features or functionality in a separate microservice.
  • Extract the new microservice from the existing Monolithic code base.

In this approach, if there is a single monolithic application, new features should be developed in a microservice that contains the separate database and functionality. In this process, if you want any data from the monolithic application, Relative APIs should be built inside the Monolithic App or a new standalone application should be created which will be responsible to just serve the monolithic application.

It is called a glue, which will become a mediator between monolithic and microservices. After this, when the developer has time, they can move the modules from monolithic to the new microservices. After a certain period of time, one can have only microservices without any monolithic application.

Suppose there is one Food Order and Delivery Management Monolithic application and someone wants to strangle that application into microservice by extracting some functionality into a microservice, the image below figure shows what a person needs to do when they have to extract some functionality from monolithic app into microservice:

Extracting functionality from monolithic app into microservice


1. First, Split the code within the Monolithic Application. Meaning, divide the code separately like Order Code and Delivery Code which will be loosely coupled code and reside in same monolithic application

Split the code


2. Split the Database and separate the database of the extracted service. Here, one should have to add integration glue. This means that a developer has to create a plan to sync between two databases. It can be managed by Triggers or by Code.

Split the database


3. Define the Separate Service for the Functionality that you want to separate. Here, it is Delivery Management. So, create a separate service for that module.

Define a service


4. Use Extracted Service as a standalone service. This can be achieved by API gateway. So, API gateway will be responsible to accept the required and divert that request to Monolithic app or newly extracted service.

Use delivery service


5. Now it’s time to remove the delivery management code from existing Monolithic Application

Delete old code


Wrapping Up

By following these steps, one can migrate a typical monolithic application into a microservice-based architecture. If you haven’t noticed, having an ideal monolithic to microservices migration strategy is crucial. Without it, the cloud migration process could be chaotic.


Comments

Popular posts from this blog

Microservice: Create JPA App Using Jakarta Persistence API in Payara Micro

How to Improve Decision Making With Better Data Quality

How to build a project in eclipse developed in Oracle JDeveloper with oc4j