{"canonical_url":"https://engineer.company/glossary/modular-monolith/","content_markdown":"# Modular monolith\n\n## What it is\n\nA modular monolith is an application delivered as one deployable unit and\norganised into modules with explicit responsibilities. Each module exposes a\nboundary that other modules can use. For example, an order module can own order\nstate, and a billing module can own invoices. The code that creates an invoice\nuses a defined billing operation. The billing module decides how its rules and\nrecords implement that operation.\n\nThe deployment shape and the code boundaries each have a role. Modules can\ncommunicate within the same process through calls or application events. They\ncan share infrastructure and a release procedure. The design still gives each\nmodule authority over its data and rules. A single database can contain tables\nowned by different modules, with agreed rules about which module may change each\ntable.\n\nTeams enforce modularity through the language's package rules, static analysis,\ntests and code review. A structural test can identify a prohibited dependency or\na cycle. A behavioural test can exercise a module through its public calls. The\npatterns are useful when a maintainer can find the owner of a decision and\nchange its implementation without having to search through unrelated packages.\n\n## Why it matters\n\nA product can be difficult to change when many components know about the same\ninternal fields. A pricing rule can appear in a route, a batch job and a report.\nEach reader may make different assumptions about which changes are allowed.\nPutting that rule behind one module boundary gives callers one way to ask for\nthe result and one place to discuss its meaning.\n\nA single deployable can also simplify the operation of parts that change\ntogether. Internal calls can follow ordinary application interfaces, and some\nbehaviour can use a shared database transaction when the design intentionally\nneeds one. Team ownership still matters. The service needs a way to identify\nwhich module caused a failure, and each module should have a clearly defined\nreason for relying on other parts.\n\nThe architecture involves trade-offs. Modules released together share a\ndeployment and some runtime failure modes. A module that needs independent\navailability, scaling or ownership may eventually justify a different boundary.\nKeeping dependency direction and data ownership explicit makes that decision\neasier to evaluate. Measure the workload and the release constraints before\nchanging the deployment shape.\n\n## What it looks like in practice\n\nImagine a scheduling product with reservations and billing. The reservations\nmodule records an accepted booking and exposes a stable identifier. Billing can\nretrieve the information needed for an invoice through an expressed contract. If\nbilling stores an invoice, its own module enforces the invoice rules. A code\nreview can check that reservation handlers avoid writing billing records\ndirectly.\n\nTest a malformed request, a completed booking and a case where billing work\nfails after the reservation is recorded. The way these related operations share\na transaction or communicate through an event should follow the product's\nobligations. If billing can run later, record enough information to repeat the\nwork and inspect its outcome. A structural check can make sure the modules do\nnot consume one another's private implementation types.\n\nEngineer's\n[maritime platform architecture case study](/portfolio/a-maritime-platform-built-in-clean-layers/)\ndocuments three layers with separate responsibilities and review-enforced\nboundaries between them. A layer is defined by a kind of work, while the\nillustrative modules here follow areas of product behaviour. Both design choices\nbenefit from contracts that make responsibility clear. A billing use case can\nhave its own presentation and persistence code while the business owner of the\ninvoice remains easy to identify.\n\nKeep a small inventory of the modules that have to change for a release. A\nchange to invoice numbering can exercise billing's contract with reservations\nwithout requiring unrelated product code to understand the new rule. Look at the\nshape of integrations and their tests. If routine changes repeatedly need\npermission from several module owners, investigate whether the boundary supports\nthe actual decisions the team makes.\n\n## Where it goes wrong\n\nPackages can be named as modules while callers import everything and access each\nother's tables directly. The directory layout then offers little protection when\na rule changes. Use a small public interface and test the intended dependency\ndirection. Review operations that touch another module's records and establish\nwhich module owns the durable decision.\n\nA shared runtime can make signals difficult to assign. Attach the module and\noperation to logs or traces where error investigation depends on it. A billing\nproblem may show up as a slow booking request if the end-to-end path waits for\nbilling. A small, representative test can check the returned booking state and\nidentify which module had to respond. During review, ask whether a production\nobservation will help a maintainer find the owner of an unusually slow or\nunsuccessful step.\n\nEvents can hide a dependency too. A module might publish a notification and\nassume the work was completed by the time a caller reads the next page. State\nwhich effects are synchronous, which are deferred and how to observe a failure.\nKeep enough detail to test the overall use case as well as the behaviour inside\nan individual module.\n\nFinally, watch for shared infrastructure that develops into a home for unrelated\nbusiness rules. A common utility can make the system simpler when it contains\nstable reusable behaviour. A shared database procedure that owns decisions from\nseveral domains can make accountability harder. Review ownership with the people\nwho operate the feature and keep examples of expected behaviour near the\nboundary. A module is useful when it helps a team explain where a rule lives and\nwhat changes when that rule evolves.\n\n## Further reading\n\n- [Spring Modulith fundamentals](https://docs.spring.io/spring-modulith/reference/fundamentals.html).\n  Describes application module boundaries and exposed parts.\n- [Spring Modulith structural verification](https://docs.spring.io/spring-modulith/reference/verification.html).\n  Shows how architecture rules can be checked.\n- [Spring Modulith application events](https://docs.spring.io/spring-modulith/reference/events.html).\n  Discusses event publication and delivery within an application.\n\n\u003chttps://engineer.company/glossary/modular-monolith/\u003e\n","date_modified":"2026-11-25T07:18:46Z","description":"Separate order and billing responsibilities in one deployable application and check that their boundaries hold.","formats":{"gemtext":"https://engineer.company/glossary/modular-monolith/index.gmi","gopher":"https://engineer.company/glossary/modular-monolith/gophermap","html":"https://engineer.company/glossary/modular-monolith/","json":"https://engineer.company/glossary/modular-monolith/index.json","markdown":"https://engineer.company/glossary/modular-monolith/index.md","pdf":"https://engineer.company/glossary/modular-monolith/index.pdf"},"kind":"page","language":"en","title":"What is a modular monolith?","url":"https://engineer.company/glossary/modular-monolith/","version":1}