Part 5 of 7 · 3 min read
Domain partitioning and the modular monolith
Group by business area instead of by technical job, and stay one deployment.
Think of two ways to arrange a library. One puts all the covers in one room, all the pages in another and all the bindings in a third. The other puts everything about cooking in one room and everything about travel in another. For finding things by subject, the second is better.
FSA calls the second domain partitioning. The top-level components are business workflows or areas, such as Catalog Checkout, Promotion and Delivery. Each component may have internal layers, but the top-level split follows the domain. Simon Brown popularised the modular monolith: one deployment unit with one database, partitioned around domains.
Domain partitioning
Domain partitioning groups code by business area or workflow, and each group contains everything that area needs.
Example: a checkout module holds its own screens, rules and database access, and a catalog module holds its own.
Modular monolith
A modular monolith is a single deployed application whose code is divided into modules by business domain, with clear boundaries between modules.
Example: a web shop deployed as one program, with separate catalog, checkout and delivery modules that may call each other only through small public interfaces.
The book compares the two partitionings. In the technical layout, the Catalog Checkout workflow shows up in every layer. In the domain layout, it lives in one component. The book sees a trend over recent years toward domain partitioning in both monoliths and microservices, because it matches how changes usually come: by business feature.
| Technical partitioning | Domain partitioning | |
|---|---|---|
| Top-level groups | Presentation, business, persistence | Catalog, checkout, delivery |
| Finding all code of a feature | Search every layer | Look in one module |
| Match with teams | By skill (UI team, DB team) | Cross-functional teams per domain |
| Effect of a change to one feature | Touches all layers | Mostly one module |
| Effect of a change to the database technology | Mostly one layer | Touches every module |
| Fit with microservices later | Poor | Close |
The book names the Inverse Conway Maneuver, coined by Jonny Leroy: if the structure of teams shapes the architecture, change the team structure on purpose to get the architecture you want. Domain partitioning makes it easy to build cross-functional teams, each owning a domain.
Ready to split. In the Silicon Sandwiches case study, the book describes a modular monolith with one relational database. It advises that, if time and resources allow, the architect should separate the tables and other database assets in line with the domain components. Then the application can move to a distributed style more easily if needs change. The same advice appears in Building Microservices, which suggests modelling each business area as a module inside the process and keeping the new system on the monolithic side until the area's boundaries are stable. Page 6 explains why.
A worked example (made up). A shop has three modules: catalog, checkout, delivery. The rules:
| Rule | Purpose |
|---|---|
Checkout may call catalog only through CatalogApi |
Boundary stays small |
Each module owns its own tables with a prefix (catalog_, checkout_) |
Data can be moved with the module |
| No module reads another module's tables | No hidden coupling |
| A build test fails if a module imports another's internal classes | The rule is checked by a machine (a fitness function) |
These rules cost a little discipline. They keep the cost of a future split low.
Read it as
A modular monolith has the deployment simplicity of one unit and the boundaries of services. The boundaries are enforced by rules and tests instead of by the network.
Check yourself:
- What does domain partitioning change about where the "checkout" code lives?
- Why separate database tables by module even when there is a single database?