architecting   modular monolith  

How modular can your monolith go? Part 1 - the basics

This article is the first in a series of articles about modular monoliths. The other articles are:

The first rule of migrating to microservices is don’t. Instead, you should make the most of your monolith. Even though a large monolith might not resolve the dark matter energy, especially multiple technology stacks, the monolithic architecture not an anti-pattern. A key question is, therefore, what’s the most effective way of structuring your monolith?

The traditional layered architecture

Over the years, I’ve started development of many monolithic application by doing the equivalent of:

mkdir application
cd application
mkdir web domain persistence

The monolith is structured as three technically oriented layers:

  • web - the user interface and/or API logic
  • domain - the business logic
  • persistence - the database access logic

This works well for small applications but as the number of developers grows it becomes increasingly problematic.

The trouble with technical layers

The trouble technically-oriented architecture is that it doesn’t mirror the structure of the application’s development organization. A large development organization should be structured as collection of small, cross-functional teams (ie. Team topology’s stream aligned teams), each of which is responsible for a particular business (sub)domain. For example, let’s imagine that the FTGO application consists of three teams/domains:

  • customers - manages customers
  • orders - manages orders created by customers
  • notifications - delivers notifications (e.g. email, SMS, etc) to customers

Each subdomain consists of web, domain and persistence logic. But since the monolith is structured around the technical layers, the code for each subdomain is scattered across the technical layers. For example, the persistence module would contain classes such as CustomerRepository, and OrderRepository. Similarly, the domain module would contain classes such as Customer, and Order. Finally, the web module would contain classes such as CustomerController, and OrderController. As a result, teams are forced to work across the technical layers, which can be a source of friction that reduces productivity.

Moreover, it’s likely that this way of structuring the monolith will result is a slow deployment pipeline, since a change to a class belonging to one subdomain, e.g OrderRepository will require classes belonging to other subdomains to be tested as well.

The modular monolith

A better way to organize a monolith is to structure it around the business domains rather than the technical layers, the so-called modular monolith architectural style. For example, the development of the application described earlier would start by doing the equivalent of:

mkdir application
cd application
mkdir main customers orders notifications
cd customers
mkdir web domain persistence
...

The main module is the entry point to the application.

Improved team autonomy and faster builds

In a modular monolithic, the code based mirrors the domains. As a result, Team autonomy is improved since each team is working on a distinct part of the code base.

This architectural style can also accelerate the deployment pipeline since a change to a class belonging to one subdomain will (hopefully) only require classes belonging to the same subdomain to be tested.

But how to implement operations that span multiple domains?

One key question that I haven’t yet addressed is how to implement operations that span multiple domains. For example, createCustomer() needs to create a Customer and send out an email confirmation, which requires the customers and notifications domains to collaborate. Similarly, the createOrder() operation needs to create an Order in the orders, reserve credit in the customers domain (which can fail) and send an order confirmation using the notifications domain.

In the next article, I’ll describe the issues that you need to consider and explore the various options.

Need help with your architecture?

I’m available. I provide consulting and workshops.


architecting   modular monolith  


Copyright © 2024 Chris Richardson • All rights reserved • Supported by Kong.

About Microservices.io

Microservices.io is brought to you by Chris Richardson. Experienced software architect, author of POJOs in Action, the creator of the original CloudFoundry.com, and the author of Microservices patterns.

Chris helps organizations improve agility and competitiveness through better software architecture. Learn more about his consulting engagements, and training workshops.

Upcoming public talks/workshops

PREMIUM CONTENT

Premium content and office hours is now available for paid subscribers at premium.microservices.io.

MICROSERVICES WORKSHOPS

Chris teaches comprehensive workshops for architects and developers that will enable your organization use microservices effectively.

Avoid the pitfalls of adopting microservices and learn essential topics, such as service decomposition and design and how to refactor a monolith to microservices.

Learn more

LEARN about microservices

Chris offers numerous other resources for learning the microservice architecture.

Get the book: Microservices Patterns

Read Chris Richardson's book:

Example microservices applications

Want to see an example? Check out Chris Richardson's example applications. See code

Remote consulting session

Got a specific microservice architecture-related question? For example:

  • Wondering whether your organization should adopt microservices?
  • Want to know how to migrate your monolith to microservices?
  • Facing a tricky microservice architecture design problem?

Consider signing up for a two hour, highly focussed, consulting session.

Virtual bootcamp: Distributed data patterns in a microservice architecture

My virtual bootcamp, distributed data patterns in a microservice architecture, is now open for enrollment!

It covers the key distributed data management patterns including Saga, API Composition, and CQRS.

It consists of video lectures, code labs, and a weekly ask-me-anything video conference repeated in multiple timezones.

The regular price is $395/person but use coupon ILFJODYS to sign up for $95 (valid until March 12, 2024). There are deeper discounts for buying multiple seats.

Learn more

Learn how to create a service template and microservice chassis

Take a look at my Manning LiveProject that teaches you how to develop a service template and microservice chassis.

Signup for the newsletter


BUILD microservices

Ready to start using the microservice architecture?

Consulting services

Engage Chris to create a microservices adoption roadmap and help you define your microservice architecture,


The Eventuate platform

Use the Eventuate.io platform to tackle distributed data management challenges in your microservices architecture.

Eventuate is Chris's latest startup. It makes it easy to use the Saga pattern to manage transactions and the CQRS pattern to implement queries.

ASSESS your architecture

Assess your application's microservice architecture and identify what needs to be improved.

Consulting services

Engage Chris to conduct an architectural assessment.



Join the microservices google group

Topics

Note: tagging is work-in-process

GitOps   ·  Microservices adoption   ·  ancient lore   ·  anti-patterns   ·  application api   ·  application architecture   ·  architecting   ·  architecture   ·  architecture documentation   ·  assemblage   ·  beer   ·  books   ·  containers   ·  dark energy and dark matter   ·  deployment   ·  deployment pipeline   ·  design-time coupling   ·  developer experience   ·  development   ·  devops   ·  docker   ·  eventuate platform   ·  generative AI   ·  glossary   ·  health   ·  hexagonal architecture   ·  implementing commands   ·  implementing queries   ·  inter-service communication   ·  kubernetes   ·  loose coupling   ·  microservice architecture   ·  microservice chassis   ·  microservices adoption   ·  microservicesio updates   ·  modular monolith   ·  multi-architecture docker images   ·  observability   ·  pattern   ·  refactoring to microservices   ·  resilience   ·  sagas   ·  security   ·  service api   ·  service architecture   ·  service blueprint   ·  service collaboration   ·  service design   ·  service discovery   ·  service granularity   ·  service template   ·  software delivery metrics   ·  success triangle   ·  tacos   ·  team topologies   ·  testing   ·  transaction management   ·  transactional messaging

All content


Posts

24 Jul 2017 » Revised data patterns