Dec 10, 2019 · by Chester Pressler

Moving From Monolithic to MicroServices

A practical example

Large monolithic applications are a thing of the past. What do you do if you have one and you need to move to a more modern trends in application development? Most organizations can’t just throw away their current 24/7 application and develop a new one overnight. Therefore, migrating to a microservices based system requires you to selectively isolate portions of the monolithic application for migration.

A Practice Example

Challenges of Monolithic Applications

Many organizations, including large and small, have been faced with the same struggles over the past decade. Initial development of the monolithic application addressed the initial business needs. As time moves forward, there are business changes that will require adjustments to new market requirements such as regulatory compliance, or even changing market conditions like food ordering services.

As these new business needs are requested, there are challenges on how to integrate them into the business operations without interfering with the current business operations. Initially, additional features are easily added to the monolithic application, but over time it affects the ability to deliver new features in a timely matter since each new feature could have an impact on previous features deployed. There is no easy way to isolate and test these new features as well.

Here is a list of come of the challenges with monolithic applications.

  • Coupled dependencies – where many things depend on each other
  • Testing – Small changes force many tests. Regression tests take a long time to run
  • Entices “ Safe” changes – staff is afraid to make too many changes
  • Long release cycles – Months vs. weeks or days or even hours
  • Multiple code bases have direct access to the Database
  • Prevents changes and progression to enhanced data models

An Example Migration

Below is an example of a large monolithic application that could be in any language such as PHP or Java. Each change to the application has a potential unknown affect on another part of the system. Communication and data connections between areas of the system can be hard to manage.

Migration can be achieved in this type of application but it takes a commitment to the long term plan.

An example of an isolated migration is handling the operational data for an airline that requires information on the airports that the airlines serves flights to. In the monolithic application there might be more than 10 places in application code where the database is being accessed directly and accessing information about the airports. Initially the developers will have to understand those access points and document the data being accessed and in what mode (either read or write).

Steps to Migrate

  1. Document current access and modes ( R/W ).
  2. Develop an isolated data model. This can even be on a new database schema (preferred). If so then develop a data migration or temporary sync plan.
  3. Develop the code base. Spring Boot is an excellent framework for this conversions since most of the heavy lifting of code is handled and you can focus on the data. This also helps in long term migration to container deployments such as Docker and Kubernetes.
  4. Develop Test Coverage of the code to be 80% or greater. Tools such as Sonar help automate that process.
  5. Deploy when ready to production as individual deployments that are separate from any other monolithic deployments.
  6. Migrate monolithic code as documented in step 1 to utilize the new service. It’s best to do this over time as new monolithic releases/updates are pushed to production. Alternatively develop new user applications that work with the new micro service.

 

Developing a simple Microservice using Spring Boot

Spring Boot Initializer allows you to quickly build a microservice. By using the Spring Initializer online project generator you can be developing a microservice in less than a day. This includes the setup of the initial CRUD (Create/Read/Update/Delete) services. Custom queries are supported but in most cases the built in CRUD repository can handle most of the standard calls for data.

The Spring Boot application will handle the REST endpoints and also the basic interfacing to your database repository. This is all handled by either in class Annotations or Configuration as code. The microservice can also be integrated with a tool such as Flyway so that you can version control you database schema as well.

Testing of the Spring Boot application is made easy as well with many different test engines supported so that you can test each layer of the application as a unit and also test the complete microservice from the API level.

The Benefits of MicroServices

  • Migrating to Microservices is not always a “clear cut” approach. Changes may have to come in stages
  • Start off with one service
    • Migrate clients one at a time
  • Key is keeping related data in one service
  • Develop a caching implementation to store highly immutable data. In this example that would be “Airports” since this will rarely change
    • Could also use a message broker Pub/Sub to invalidate caches when a new/update occurs.
  • Develop greater than 80-85% test coverage in your micro services code
    • Allows high level of confidence in redeployments
    • New errors become new test cases

Migration to a microservices architecture will take time. As long as you develop a long term vision you will rapidly increase the conversion velocity and you will slowly “strangle” your current monolithic to the bare minimum or you will no longer need to use it.

Here are some conclusions to consider going forward.

  • Faster development cycle for new services due to isolated code development and testing. Consider Spring Boot framework since it can do some heavy lifting of core functionalities. Spring Boot Initializer
  • Better isolation of code functionality to minimize complex testing of the code changes
  • Microservices allows for continued isolated deployments as well as providing a scalable architecture for periodic load changes (such as Cyber Monday sales)
  • Hybrid capabilities to offload some compute onto a cloud service

Watch for some follow up articles that go a bit more in depth with some of the technologies to use in the migration.

……………………………………………………………………………………………………………………………………………………………………………………

About the article

On September 2019, Cognizant Softvision celebrated the 5th edition of Programmers’ Week, a global event where more than 140 speakers delivered technical-talks from Argentina, US, Canada, India, Ukraine and Romania. Chester, who is based in Las Vegas, delivered a presentation about moving from monolithic to microservices.

Chester Pressler

Technical Director / Studio Manager

Latest posts by Chester Pressler

Share This Article

Post A Comment

FacebookInstagramLinkedInTwitter