Monolith First Approach Before Moving to Microservices

In this article, we are going to learn Monolith First Approach when designing any application before moving to microservices.

Modular Monolithic Architecture

By this article, we are going to learn Monolith First Approaches from Martin Fowler and Sam Newman. After that we will evaluate this approach with comparing to start from microservices architecture.

I have just published a new course — Design Microservices Architecture with Patterns & Principles.

Monolith First Approaches, Martin Fowler

Let me start with Martin Fowler, Martin Fowler has article about MonolithFirst which written 2015:

In this article, he is said that:

Almost all the successful microservice stories have started with a monolith architectures that got too big and was broken up. Almost all the cases where the system that was built as a microservice system from scratch, it has ended up in serious trouble.

You shouldn’t start a new project with microservices, even if you’re sure your application will be big enough to make it worthwhile. Microservices are a useful architecture, but even their advocates say that using them incurs a significant complexity, which means they are only useful with more complex systems.

  • The first reason for this is classic YAGNI. When you begin a new application, how sure are you that it will be useful to your users ?
  • The second issue with starting with microservices is that they only work well if you come up with good, stable boundaries between the services — which is essentially the task of drawing up the right set of BoundedContexts.

There are different ways to execute a Monolith-first strategy. The logical way is to design a monolith carefully, paying attention to modularity within the software, both at the API boundaries and how the data is stored. So these are the ideas of Martin Fowler about MonolithicFirst approaches from his article.

Monolith First Approaches, Sam Newman

Second quotation from Sam Newman book which is — Building Microservices, 2nd Edition.

Sam Newman, in the book “Building Microservices”, agrees with the Martin Fowler approach which is recommend beginning development of new projects and systems as a single deployable unit — the Monolith.

He recommends leveraging microservices only if you can become convinced of the benefits for your system, not as a default for every project.

A monolithic architecture is a choice, and a valid one at that. It is the sensible default choice as an architectural style. In other words, looking for a reason to be convinced to use microservices, rather than looking for a reason not to use them. Sam Newman — Building Microservices, 2nd Edition

Monolith First Approaches, Mehmet Ozkaya

So let me say what I am thinking of this topic ? Monolithic architecture does not means that the system is poorly designed or bad. Instead if you follow Modular approach, it will comes with lots of similar benefits with microservices like re-usability, easy to refactor, better organized dependencies and teams. Also it will avoid microservices complexity like underlying infrastructure management and deployment complexity providing with exactly one deployment unit.

  • So Should we always start with Monolith First Approaches ?
    NO.

How we can decide ?

  • If Strong Consistency is Mandatory && Independent Scale and Deploy is not Required = Modular Monolithic
  • If Strong Consistency is not Mandatory, Eventual Consistency is OK && Independent Scale and Deploy is Required = Microservices

These are my opinions that could not always correct and it always depend on your project requirements. As we always said when you design your architecture you should consider all FR and N-FR with together and drive your architecture with these concepts.

From Kelsey Hightower

Lets continue to a tweet thread from Kelsey Hightower.

https://twitter.com/kelseyhightower/status/1621184564956893189
https://twitter.com/kelseyhightower/status/1621184564956893189

Here you can see that Kelsey go one more step and offers that if we follow Modular Monolithic Architecture and build on Serverless and fully managed components, this would be prefect architecture most of software projects.

I also strongly agree with Kelsey for most of cases, but of course in some cases Microservices are un-avoidable chooses for large-scaled applications. The idea from Kelsey is that if you start with that setup, it can evolve and scale very easily for future requirements.

It is important to note that a Modular monolithic architecture is not a replacement for microservices architecture. Both approaches have their strengths and weaknesses, and the choice of architecture depends on the specific requirements of the system being built. A modular monolithic architecture can be a good starting point for a system that may eventually need to evolve into a microservices architecture as the system grows and complexity increases.

Design Modular Monolithic Architecture — E-Commerce App

If we design e-commerce application with Modular Monolithic architecture, you can see the image below:

Modular Monolithic Architecture

According to architecture, we can encapsulate new feature developments into a module. And every module can implement its own architecture like Layered, Onion, Clean and so on.

Design Microservice Architecture — E-Commerce App

If we design e-commerce application with Microservice architecture, you can see the image below:

Microservices Architecture

Product microservice can use NoSQL document database Shopping Cart microservice can use NoSQL key-value pair database and Order microservice can use Relational database as per microservice data storage requirements.

What’s Next ?

Step by Step Design Architectures w/ Course

I have just published a new course — Design Microservices Architecture with Patterns & Principles.

In this course, we’re going to learn how to Design Microservices Architecture with using Design Patterns, Principles and the Best Practices. We will start with designing Monolithic to Event-Driven Microservices step by step and together using the right architecture design patterns and techniques.

--

--

Mehmet Ozkaya
Design Microservices Architecture with Patterns & Principles

Software Architect | Udemy Instructor | AWS Community Builder | Cloud-Native and Serverless Event-driven Microservices https://github.com/mehmetozkaya