Modular monolith boundaries
Modular monolith boundaries
A modular monolith deploys one application while preserving explicit module contracts and ownership. It is not simply a large application with many folders.
A bounded context is a language and model boundary; a module is a code and ownership boundary. They often align but are not identical, and a module does not have to be a separate service. Catalog owns product descriptions and prices; Fulfillment owns reservation and shipment rules. Share IDs or small stable DTOs, not mutable domain objects or each other's persistence tables. A direct in-process contract avoids network failures and is easy to deploy but still couples modules to contract versions. A single relational database may host separately owned tables; crossing boundaries with a shared transaction is a deliberate coupling decision, not an automatic benefit of monolithic deployment. If two modules cannot commit atomically, use an explicit pending state, retry or compensation; do not promise exactly-once. A versioned contract and mapping isolate terminology differences. An internal visibility modifier helps enforce assembly boundaries, while namespaces alone do not. Project-reference rules and tests detect accidental dependencies, but cannot prove a module never accesses another's tables. Use an ADR to choose a single deployment until independent scaling, ownership or availability needs justify service extraction. The companion lab uses three projects and explicitly maps a catalog item to fulfillment; it is package-free and has no real database.
Baseline: .NET 10 / C# 14. All C# results below are reasoned, not executed. Offline models and multi-project labs are explicitly distinguished.
Translate between module contracts
Catalog publishes a value snapshot. Fulfillment translates it into its own request and does not mutate catalog state.
Use the archived Fixture.csproj with an approved .NET 10 SDK. No third-party packages are required. Inspect the project, then build and run with the approved SDK.
using System;var item = new CatalogItem("SKU-A", true);var request = Map(item, 2);Console.WriteLine($"{request.Sku}: {request.Units}");try { Map(new CatalogItem("SKU-B", false), 1); }catch (InvalidOperationException) { Console.WriteLine("not orderable"); }static ReserveRequest Map(CatalogItem item, int units) { if (!item.Orderable || units <= 0) throw new InvalidOperationException("Invalid request"); return new ReserveRequest(item.Sku, units);}sealed record CatalogItem(string Sku, bool Orderable);sealed record ReserveRequest(string Sku, int Units);Expected result (not executed):
SKU-A: 2not orderableA snapshot is not a lock or current stock guarantee. Fulfillment validates its own invariant when accepting the request. In a real module define contract ownership and version policy.
Keep a pending state when another module rejects
A model shows that accepting a catalog order is not the same as confirming fulfillment. No actual persistence or messaging occurs.
Use the archived Fixture.csproj with an approved .NET 10 SDK. No third-party packages are required. Inspect the project, then build and run with the approved SDK.
using System;foreach (int available in new[] { 3, 1 }) { var order = new Order("pending", 2); var result = TryReserve(available, order.Units); order = order with { Status = result ? "confirmed" : "needs review" }; Console.WriteLine(order.Status);}static bool TryReserve(int available, int units) => units > 0 && units <= available;sealed record Order(string Status, int Units);Expected result (not executed):
confirmedneeds reviewThe pending model makes a partial outcome visible instead of reporting fulfillment success. Real retries need stable IDs and an atomic persistence plan; this model does not reserve anything.
Check an explicit dependency rule
A simple graph describes allowed project references. A forbidden direct dependency from Catalog to Fulfillment is detected. The companion project lab checks actual XML references separately.
Use the archived Fixture.csproj with an approved .NET 10 SDK. No third-party packages are required. Inspect the project, then build and run with the approved SDK.
using System;using System.Collections.Generic;var allowed = new HashSet<(string From, string To)> { ("Host", "Catalog"), ("Host", "Fulfillment") };foreach (var edge in new[] { ("Host", "Catalog"), ("Catalog", "Fulfillment") }) Console.WriteLine($"{edge.Item1} -> {edge.Item2}: {allowed.Contains(edge)}");Expected result (not executed):
Host -> Catalog: TrueCatalog -> Fulfillment: FalseThis model treats the host as the orchestrator and modules as independent projects. A shared contracts project may be justified when the dependency is intentionally owned. The allowed set must be versioned and checked against real project files.
Apply the concept
Design a catalog and fulfillment split for a fictional order. Describe the public contracts, table ownership, a rejected reservation, and the condition for a shared transaction or separate durable workflow.
Use the manual practice and knowledge check. Do not deploy or publish these fixtures.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Modular monolith boundaries — knowledge check
Apply the lesson concepts to the following scenarios.
What differentiates a modular monolith from a microservice deployment?
Which artifact is best for a module to expose?
When is a cross-module shared transaction reasonable?
What can a project-reference test detect?
A fulfillment request fails after order acceptance. What should the workflow expose?