Breaking a Monolith into Microservices - Best Practices and Challenges


Image


In this article, we will describe the first steps, in taking an architecture from monolith to microservice.

You will learn

  • What are the important features of microservices architectures?
  • What are the important challenges?
  • How do you break a monolith to microservices?

Let’s start with the basics of a monolith architecture, understand the microservices architecture, and figure out what should you do to migrate from the former to the latter.

Free Courses - Learn in 10 Steps

Monolith Architecture

The salient features of monolith applications are:

  • Released, or taken to production, once every few week or months or years
  • Generally have a wide range of features and functionality
  • Have a development team of over 50 people working on them
  • Debugging problems that arise in them, is a huge challenge
  • It is almost impossible to bring in new technologies and technical processes, midway through the lifetime of such an application

Monolith applications are typically huge, with them having a million lines of code on average.

A monolithic application would look something like the following:

image info

You have a large application talking to a large database.

Microservices Architecture

In microservices architectures, instead of building a large application, we build a number of smaller microservices.

Here is how you would split up the monolith MovieApplication:

image info

As you can see here, the databases are also separated out.

Microservices architecture involves a number of small, well-designed microservices, that exchange messages among themselves: image info

Microservices Architecture Is Tough

While a microservices architecture looks very easy at a high level, implementing it is not a trivial process at all.

There are a number of important decisions to make for moving to Microservices Architectures

Examples:

  • What are the boundaries of the individual microservices?
  • How small should a microservice be, and what functionality should go into it?
  • What all data needs to go into the database that a particular microservice talks to extensively?
  • How should the microservices communicate with each other?

Challenges with the Microservices Architectures

The challenges that need to be tacked when setting up a microservices architecture are described below.

Quick Setup Needed

You can NOT spend a month setting up each microservice. You should be able to setup a microservice quickly.

Automation

Because there are a number of smaller components instead of a monolith, there needs to be automation in every activity, such as builds, deployment, monitoring, etc.

Visibility

You have a potentially large number of smaller components to deploy and maintain. This number could be 100 today, and a 1000 tomorrow. You should be able to monitor and identify problems automatically. You need great visibility around all the components.

Bounded Context

Deciding the boundaries of a microservice is not an easy task. Applying Bounded Context principles from Domain Driven Design is usually a good starting point.

Your understanding of the domain evolves over a period of time. You need to ensure that the microservice boundaries evolve with time.

Configuration Management

You need to maintain configurations for hundreds of components across environments. It would be best to have a configuration management solution.

Dynamic Scale Up And Scale Down

The advantages of a microservices architecture can be realized only of the application can scale up and scale down easily in the cloud.

Pack Of Cards

If the microservice at the bottom of a call chain fails, it can have knock on effects on all the other microservices. Microservices should be fault tolerant by design.

Debugging

When there is a problem that needs investigation, you might need to look into multiple services across different components. Centralized logging ans dashboards are essential to make it easy to debug problems.

Consistency

You cannot have a wide range of tools solving the same problem. While it is important to encourage innovation, it is also essential to have decentralized governance around the languages, platforms, technologies and tools used for implementing, deploying and monitoring microservices.

Going from Monolith To Microservices - It is Not A Switch

You may have noticed that after describing monolith applications, we directly jumped into the challenges of microservices.

The reason we did not first talk about the advantages of microservices, is that you need a reality check when you migrate from one architecture to another. You need to realize this is not something you can do in a few weeks or months.

Getting a microservices architecture right involves a few years of work. It’s not a switch, but a journey.

During that journey, both architectures live side by side.

You would hope that number of applications using the microservices architecture grows over time.

Ask Why are you migrating From Monolith To Microservices

This is the most important question to ask! Don’t do microservices because it is a buzzword. Do it because your business needs it.

Why are you migrating from Monolith to Microservices?

What do you want to achieve?

  • Do you want to be able to adopt new technologies and processes, in a faster manner?
  • Do you want faster release cycles for your application?
  • Do you want to scale more easily in the cloud?

You need to be very aware of which of these reasons is the biggest one, for your migration.

The approach you use to actually migrate would differ, based on the exact reason for migration.

Let’s look at these approaches in a little more detail.

If your reason is - to Adopt New Technologies

Let’s say the reason is the ability to adopt newer technologies. In that case, you can start off with designing microservices for the next set of features you intend to implement. In other words, all the requirements for new feature implementation in the monolith application, are the best candidates to become microservices.

You need to answer questions such as:

  • How do you design the database?
  • How do make sure the communication between the old monolith and the new components, is proper?
If your reason is - to have Faster Release Cycles

Your business may not be happy with the pace at which new features are being released to production. In that scenario, you first need to identify those parts of the application, where there are frequent changes.

Once you do this, you can extract the fast moving parts and create microservices around them.

The idea behind this is , when there is a change, only release the related microservice.

If your reason is - to Scale With The Cloud

If the driving force behind the migration is scaling with the cloud, then you need to analyze what needs to be done to put your application in the cloud.

Start with research and Proof-of-Concept prototypes to understand the dependencies involved. You need to find out which dependencies are important to break, and anticipate the problems you may face on making the application cloud-native.

More than one

Your business might need more that one of the above. Prioritize them and get started with the most important ones.

Clearly, the path to migration will not be the same for all. However, with whatever microservices that you design in your journey, make sure they address the challenges that we saw earlier, in an effective manner.

Do check out our video on this:

image info

Summary

In this article, we had a good look at the activities involved in moving from a monolith to a microservices architecture. We observed that it is not an easy journey, as the though process involved in designing the two kinds of systems, is radically different.

The actual journey of your migration will heavily depend upon the exact reason why you want to do it. Ultimately, with whatever microservices you come up with, make sure they effectively address the challenges that exist in such a system.

Best Selling Udemy Courses

Image
Image Image Image Image Image Image Image Image Image

Join 450,000 Learners and 30+ Amazing Courses

350,000 Learners are learning everyday with our Best Selling Courses : Spring Boot Microservices, Spring, Spring Boot, Web Services, Hibernate, Full Stack React, Full Stack Angular, Python, Spring Interview Guide, Java Interview, Java Functional Programming, AWS, Docker, Kubernetes, PCF, AWS Fargate and Azure


Do not know where to start your learning journey? Check out our amazing learning paths:
Learning Path 01 - Spring and Spring Boot Web Applications and API Developer,
Learning Path 02 - Full Stack Developer with Spring Boot, React & Angular,
Learning Path 03 - Cloud Microservices Developer with Docker and Kubernetes,
Learning Path 04 - Learn Cloud with Spring Boot, AWS, Azure and PCF and
Learning Path 05 - Learn AWS with Microservices, Docker and Kubernetes


Subscribe

FREE COURSES



Related Posts

Writing Integration Tests for Rest Services with Spring Boot

Setting up a basic REST Service with Spring Boot is a cake walk. We will go one step further and add great integration tests!

Integrating Spring Boot and Spring JDBC with H2 and Starter JDBC

Learn using Spring Boot Starter JDBC to connect Spring Boot to H2 (in memory database) using Spring JDBC. You will create a simple project with Spring Boot. You will add code to the project to connect to a database using Spring JDBC. You will learn to implement the basic CRUD methods.

JUnit Tutorial for Beginners in 5 Steps

JUnit Tutorial for Beginners in 5 Steps. Setting up a basic JUnit example and understanding the basics of junit.

JPA and Hibernate Tutorial For Beginners - 10 Steps with Spring Boot and H2

JPA and Hibernate in 10 Steps with H2 - Setting up a basic project example with Spring Boot and in memory database H2. Its a cake walk.

Spring Boot Tutorial For Beginners in 10 Steps

Introduction to Spring Boot in 10 Steps. Learn the basics of Spring Boot setting up a basic project example with Spring Boot.

Spring Framework Tutorial for Beginners - Your First 10 Steps

Learn the basics of Spring Framework setting up a very simple example.

JPA and Hibernate Tutorial using Spring Boot Data JPA

Complete journey starting from JDBC to JPA to Spring Data JPA using an example with Spring Boot Data JPA starter project. We use Hibernate as the JPA Implementation.

Creating a Web Application with Spring Boot with JSP

Setting up a basic web application with Spring Boot is a cake walk. We will create a simple web application using Spring Initializr and add JSP features to it.

What is Spring Boot Auto Configuration?

Auto Configuration is the most important feature in Spring Boot. In this tutorial, we will learn important concepts about Auto Configuration with a couple of examples.

Unit Testing Rest Services with Spring Boot and JUnit

Setting up a Basic REST Service with Spring Boot is a cake walk. We will go one step further and add great unit tests to our RESTful Service.


Search