0
votes

To anyone with real world experience breaking a monolith into separate modules and services.

I am asking this question having already read the MonolithFirst blog entry by Martin Fowler. When taking a monolith and breaking it into microservices the "size" element of the equation is the one that I ponder over the most. Specifically, how to approach breaking a monolith application (we're talking 2001: A Space Oddessy; as in it is that old and that large) into micro services without getting overly fine grained or staying too monolithic. The end goal is creating separate modules that can be upgraded indepenently and scaled independently.

What are some recommended best practices based on personal experience of breaking a monolith into microservices?

3

3 Answers

2
votes

The rule of thumb is breaking the monolith based on bounded context . The most common way of defining the bounded context is using BU ( Business Unit) . For example the module which does actual payment is mostly a separate BU .

The second thing to consider is the overhead micro-services bring. You should analyse the hardware , monitoring , infra pieces before completely breaking the service. What I have seen is people taking smaller microservices out of monolith instead of going and writing say 10 new service and depreciating the monolith.

My advice will be have an incremental approach . Take the first BU which is being worked upon out of monolith. This will also give a goos learning curve for the whole team.

2
votes

You should clearly distinguish sub-domain areas (bounded contexts) from you domain.

Usually (if everything is fine with your architecture) you already have some separate components in your monolith application which responsible for each sub-domain. These components interact with each other in one process (in monolith application) and you should to think about how to put them into separate processes. Of course you need to produce a lot of refactoring when moving one by one parts of the monolith to microservices.

Always remember that every microservice is responsible for some sub-domain.

I strongly recommend you to learn Domain Driven Design.

Also learn CQRS pattern

At the beginning you also should decide how your micservices will interact with each other. There are several options:

  • Direct calls from one service to another
  • Send messages through some dispatcher service which abstracts the client service from the knowledge where the called (destination) services are located. This approach is similar to how proxy server like NGINX works.
  • Interact through some messaging bus (middleware), like RabbitMQ

You can combine these options, for example Query requests can be processed through Dispatcher Service, Commands and Events through message bus.

From my experience the biggest problem will be to go away from a single database, which monolith applications is usually used.

In addition some good practices:

  • Put each microservice in own repository - this isolates from the ability to directly use the code of one micro service in another. You also get faster checkouts and builds of each microservice on CI.
  • Interactions with any service should occur only through its public contracts.
  • It is necessary to aspire that each microservice has its own database

Example of the sub-domains (bounded contexts) for some Tourism Industry application. Each bounded context can be serviced by a microservice.

Application sub-domains

1
votes

We also started our journey some time back and i started writing a blog series for exactly the same thing: https://dzone.com/articles/how-i-started-my-journey-in-micro-services-and-how

Basically what i understood is to break my problem in diff. microservices, i need a design framework which Domain Driven Design gives(Domain Driven Design Distilled Book by Vaugh Vernon).

Then to implement the design (using CQRS and Event Sourcing and ...) i need a framework which provides all the above support.

I found Lagom good for this.(Eventuate , Spring Microservices are some other choices).

Sample Microservices Domain analysis using Domain Driven Design by Microsoft: https://docs.microsoft.com/en-us/azure/architecture/microservices/domain-analysis

One more analysis is: http://cqrs.nu/tutorial/cs/01-design

After reading on Domain Driven Design i think lagom and above links will help you to build a end to end application. If still any doubts , please raise :)