The word monolith gets used as an insult, so start with what it describes. James Lewis and Martin Fowler describe an enterprise application as three parts: a user interface, a database, and a server-side application that handles requests, runs the domain logic and reads and writes the data. That server-side application is a monolith when it is one logical executable. Every change, however small, means building and deploying the whole of it.
The online shop of the first module is a good example. Catalogue, cart, ordering, payments and shipping are code in one program. They call each other as method calls, they usually share one database, and they ship together.
Mental model. A monolith is one unit of deployment. How tidy the code is inside that unit is a different question, and the rest of this lesson is about keeping the two apart.
Calls between the parts are in-process calls: no network, no serialisation, no timeout to choose, and no chance that the other side is down while this side is up. A change that crosses three parts is one commit, one review and one release. And with one database, one transaction can change the stock, the order and the payment record, and either commit all three or undo all three.
Martin Fowler’s advice, which he calls monolith first, comes from a pattern he noticed: almost all the successful microservice stories started with a monolith that got too big and was broken up, and that almost all the systems he had heard of that were built as microservices from scratch ended up in serious trouble. He gives two reasons. The first is that you do not yet know whether the product will be useful, so speed of feedback matters more than a structure for scale you may never reach. The second is that services only work well with good, stable boundaries between them, and even experienced architects find it hard to draw those at the beginning. Moving code between modules of one program is cheap. Moving it between services is not.
That is the argument for starting with one deployable. It is not an argument for leaving it a tangle.
A system answers two separate questions. How is the code organised? It can be tangled, where any part may call or read the data of any other, or modular, where parts hide their insides behind a public interface. How is it deployed? As one unit, or as many.
One deployable
Many deployables
Tangled code
The plain monolith that is hard to change
Services that must be changed and released together: the worst of both
Modular code
Modular monolith
Microservices
The bottom-left cell is the subject of this lesson. The top-right cell deserves its warning: split a tangled system into services and you keep the coupling and add a network. Segment described this experience, with many services that had to be changed together because of shared libraries, and merged them back into one.
A modular monolith is still one deployable, but its code is divided into modules, each owning a part of the domain, with these properties:
a public interface: the only way other modules may use it;
its own data: the tables of a module are read and written by that module alone, and others ask it;
enforced boundaries: a tool or a test fails the build when a module reaches into another. Shopify’s open-source Packwerk, for example, checks the dependencies between the packages of a Rails application.
The last point is the one that matters. Fowler is blunt about boundaries held by habit: in theory there is no reason a monolith cannot have well-defined module boundaries, but in practice it is too easy for them to be breached and for monoliths to get tangled as well as large.
Take five modules: catalogue, cart, ordering, payments and shipping. Any module could call any other, which is 5 × 4, or 20, ordered pairs. Say the design allows 6 of them: cart asks catalogue for prices, ordering asks catalogue, cart and payments, shipping asks ordering, and payments asks ordering. The other 14 pairs are forbidden, and the boundary check looks at all 20 on every build. A forbidden call fails the build on the day it is written, when it is cheap to fix. It would otherwise be found a year later, when ten other things depend on it.
What a modular monolith gives and what it does not
It keeps what made the monolith attractive: in-process calls, one transaction across modules, one thing to deploy and monitor. It adds ownership. A team can say “this module is ours” and mean it, because nobody else can reach into it. And a module with a narrow interface and its own data is the natural seam along which to take out a service later, if that ever pays off. Fowler’s caution applies: you cannot assume that any system can be broken into services, because most systems collect too many dependencies between their modules, and a monolith designed with modularity in mind is more likely to be one that can.
It does not give you independent release or independent scaling. There is still one build, one deployment and one runtime.
Take the deployment first. Suppose the pipeline, from merge to production, takes 40 minutes and deploys are one at a time. In an 8-hour working day that is 480 / 40, or 12 deploys at most. Eight teams that each want to ship two changes a day ask for 16. The queue grows by 4 changes a day, and a broken change at the front holds up everyone behind it.
Now scaling. Say one copy of the application takes 2 GB of memory, of which the busiest part, the search, uses 0.5 GB and the rest 1.5 GB. To carry the peak, the search needs 8 copies’ worth of CPU, but the rest only 2. As one unit you run 8 copies: 8 × 2, or 16 GB. If the search were deployed on its own, you would run 8 × 0.5 + 2 × 1.5, which is 7 GB. These are made-up numbers, and memory is only one resource, but the shape is the point: with one deployable, the capacity of the cold parts is paid for along with the hot one. All the copies also share one database, which is the limit that the later modules on replication and sharding push back.
The explorer below holds four architecture styles and seven requirements. Hide the styles you are not interested in, tick the requirements that apply to a system you have in mind, and read the verdict on each style, with its reason. It does not pick a winner. It counts how each style measures up against what you ticked, and the reasons are the part to read. It covers the monolith, the modular monolith, microservices and event-driven communication. The next lessons take the last two apart.
Architecture styles
Which architecture style fits the number of teams, the way parts must be deployed and scaled, and the operational capacity you have today?
Every option follows the same framework: decision, why, benefits, costs, failure modes, scaling limitations, alternative.
Choosing options and requirements needs JavaScript. All the options are shown below.
Monolith
1. Decision
The whole application is built, tested and deployed as one unit, usually over one database, and its parts call each other inside one process.
2. Why?
One codebase, one deployable and one database make the simplest start: a change that crosses several parts is one commit and one release. Martin Fowler observes that almost all successful microservice stories started with a monolith that got too big and was broken up.
3. Benefits
Calls between parts are in-process method calls, which Fowler notes are cheaper than remote calls, with no network hop and no serialisation.
With one database, a single transaction can change several parts of the data at once and either commit or undo all of it.
There is one thing to build, deploy, monitor and debug, so a basic pipeline and basic monitoring are enough to start.
4. Costs
A change to a small part means the whole application is rebuilt and redeployed, as Fowler and Lewis point out.
Module boundaries tend to erode over time: nothing but discipline stops one part from reaching into another.
The whole application shares one technology stack and one release cadence.
5. Failure modes
A fault in one part can stop everything, because all parts share one process: a memory leak or an unbounded loop in a minor feature takes the whole application with it.
Every release is a shared event: a broken change blocks everyone’s deployment until it is fixed or reverted.
6. Scaling limitations
Scaling means running more copies of the whole application behind a load balancer, so capacity for a cold part is paid for along with the hot one.
All the copies share one database, which becomes the common limit; the databases, replication and sharding modules cover how to push it further.
As the number of developers in one codebase grows, merge conflicts and build and test time grow with it; Shopify’s engineers describe giving their large monolith explicit component boundaries to keep developers productive.
7. Alternative
Choose Modular monolith when several teams change the same code and the boundaries between parts start to blur, but you still want one deployable and one database.
Modular monolith
1. Decision
Still one deployable, but the code is divided into modules that each own a part of the domain and expose an explicit public interface, and the boundaries between modules are enforced by tooling or tests rather than by habit.
2. Why?
It keeps the monolith’s simple deployment and local transactions while giving teams ownership and boundaries, and it leaves each module ready to be extracted later. Fowler advises that a monolith started first be kept modular so that it can be split along clean seams.
3. Benefits
Enforced boundaries give each team clear ownership: Shopify’s open-source Packwerk tool, for example, checks the dependencies between packages of its Rails monolith.
Calls between modules stay in-process and the modules can still share one database transaction, so there is no network between them.
A module with a narrow interface and its own data is the natural seam along which to extract a service later, if that ever pays off.
4. Costs
Boundaries need discipline and tooling to stay real; without checks, a modular monolith decays into a plain one.
There is still one release train: one build, one deployment and one runtime for all modules.
Giving each module its own data means removing the joins and foreign keys that cross module boundaries, which is real work in an existing system.
5. Failure modes
Boundary violations accumulate quietly: a shortcut query into another module’s tables couples the two without any visible change in the interfaces.
A fault in one module can still stop the whole process, since all modules run together.
A schema migration for one module can lock tables that other modules use, because they share one database.
6. Scaling limitations
The unit of scaling is still the whole application, so a hot module is scaled together with the cold ones.
The shared database remains the common limit unless the data is partitioned.
Deployments are still serialised through one pipeline, so a very large number of teams queue for the same release.
7. Alternative
Choose Microservices when parts must be deployed or scaled on their own, teams are blocked by the shared release, and you have the operational capacity to run many services.
Microservices
1. Decision
The application is a suite of small services, each running in its own process, owning its data and deployable on its own; they communicate over the network, usually through HTTP APIs or messaging.
2. Why?
Independent deployability lets a team change, release, scale and roll back its service without coordinating with the others, and services organised around business capabilities line up with the teams that own them.
3. Benefits
Each service is released and rolled back on its own, through automated deployment, as long as its API stays compatible with its callers.
Only the services that need more capacity are scaled, instead of copies of the whole application.
Team boundaries and code boundaries can match, the alignment that Conway’s law and Team Topologies describe, so a team can own a service from code to production.
4. Costs
Fowler’s Microservice Premium: microservices cost productivity, and the cost is paid back only when the system is complex enough.
Each service owns its data, so there is no cross-service transaction: consistency across services is eventual and failures are repaired with compensations.
Remote calls are slower than in-process calls and can fail, so APIs are coarser grained and every call needs a timeout and a plan for failure.
Fowler lists rapid provisioning, basic monitoring and rapid deployment as prerequisites; each new service adds a pipeline, dashboards, alerts and on-call duty.
5. Failure modes
A slow service can exhaust the threads or connections of its callers along the call chain, so one degraded dependency spreads into a cascading failure.
Badly drawn boundaries give services that must change and be deployed together, which keeps the monolith’s coupling and adds the network. Segment described merging many services back into one after shared libraries made updates painful.
A multi-step change that fails halfway leaves services disagreeing until a compensation runs, or for good if none exists.
6. Scaling limitations
Operational load grows with the number of services, and each service needs its own pipeline, monitoring and on-call coverage.
A request that needs several services in sequence has, at best, the product of their availabilities, so its availability falls with every hop, and its latency adds up.
The number of services a team can own is bounded by its cognitive load, which Team Topologies treats as a design limit for architecture.
7. Alternative
Choose Modular monolith when you are not yet using independent deployment or independent scaling, and the cost of network calls, split data and operations outweighs the benefit.
Event-driven architecture
1. Decision
Components communicate by publishing events, facts that something happened, to a broker or a log; other components subscribe and react on their own, so the sender does not call them and does not need to know them. It is a way of communicating that can sit inside a monolith or link services.
2. Why?
It decouples the sender from its reactions: a new reaction is added without changing the sender, and a durable broker lets reactions happen later and at their own pace. Fowler separates several meanings of the term; this topic means event notification and event-carried state transfer, while event sourcing and CQRS are separate patterns.
3. Benefits
Loose coupling: a subscriber is added without changing the publisher, so new behaviour does not need the sender’s team.
A broker buffers bursts and consumers scale independently by adding instances that share the work, as in the competing consumers and queue-based load leveling patterns.
If a subscriber is down, events wait in the broker and are processed when it returns, so a slow or absent reaction does not block the sender.
4. Costs
The overall flow of a business process becomes implicit, spread over subscribers; Fowler warns that it is hard to see and debug.
Reactions happen after the event, so the system is eventually consistent and the interface must cope with changes that arrive late.
A broker is one more system to run, and consumers must handle duplicates and limited ordering.
5. Failure modes
With at-least-once delivery an event can be processed twice, and a consumer that is not idempotent applies its effect twice.
Saving to the database and publishing the event are two separate actions; if one fails, the data and the event disagree, which is the problem the transactional outbox solves.
A message that always fails can block a consumer, and consumer lag grows silently when consumers are slower than producers.
6. Scaling limitations
The broker is a shared dependency: its throughput and availability bound every flow that uses it.
Ordering is kept only within a partition, so parallelism and ordering pull against each other: more partitions allow more consumers but weaken the global order.
Changing an event’s format must stay compatible with every subscriber, including ones the publisher’s team does not know.
7. Alternative
Choose Modular monolith when the sender needs the combined result in the same request, or a rule must hold atomically across parts, which direct calls and one transaction give.
Nothing is ticked yet. Tick a requirement to see how each option measures up.
A young product with a small team. Tick The team has little operational capacity: observability, automated delivery and on-call practice are still basic. and A business rule must hold across several parts of the domain at the moment a change is made, so one change is applied entirely or not at all. The monolith and the modular monolith meet both. Microservices fails both: with no pipeline, monitoring or on-call to spare, each new service adds a load that the team cannot absorb, and no transaction spans services.
Many teams. Untick those, and tick Several teams own different parts of the domain, and each needs clear boundaries around its code so it can change it without constantly coordinating with the others. and A part of the system must be released, rolled back or fixed without redeploying the rest. Only microservices meets both. The modular monolith meets the first and fails the second, which is exactly what the 40-minute pipeline above showed.
The plain trade-off. Untick everything, and tick A business rule must hold across several parts of the domain at the moment a change is made, so one change is applied entirely or not at all. and A part of the system must be released, rolled back or fixed without redeploying the rest. Look at the four options: none of them meets both. The styles that give you one transaction fail the independent release, and the style that gives you the independent release fails the transaction. The rest of the module is about what it costs to push on that.
For the modular monolith, in the order the explorer uses:
Decision. One deployable, with the code divided into modules that each own a part of the domain and expose a public interface, and boundaries that a tool or test enforces.
Why? It keeps the simple deployment and the local transaction of a monolith, and gives teams ownership and boundaries. Fowler advises keeping a monolith that was started first modular, so that it can be split along clean seams.
Benefits. Clear ownership of each module. In-process calls and one transaction across modules. A module with a narrow interface and its own data is ready to be extracted.
Costs. Boundaries need discipline and tooling, or the system decays into a plain monolith. There is still one release train. Giving a module its own data means removing the joins that cross it.
Failure modes. Boundary violations pile up quietly. A fault in one module can still stop the whole process. A migration for one module can lock tables that others use.
Scaling limitations. The unit of scaling is still the whole application, the shared database is still the common limit, and deployments queue through one pipeline.
Alternative. Microservices, when parts must be deployed or scaled on their own, teams are blocked by the shared release, and you have the operational capacity to run many services.
A modular monolith without a check is a plain monolith with a tidy diagram. Suppose the shipping team needs the payment status of an order and finds it faster to query the payments tables directly than to ask the payments module. Nothing in any interface has changed, so nothing shows it. Six months later the payments team renames a column, and its own tests pass, because they test payments. Shipping fails in production. A migration of the payments tables can also lock tables that shipping reads, because they share one database.
Count the exposure. With 20 possible pairs of modules, five teams that each take one shortcut a month into a different module reach at most 5 new pairs a month, so in 4 months every pair could be coupled, and the diagram says nothing about it. This is illustrative, but the arithmetic is the point: a boundary that nothing checks lasts as long as the team’s patience.
Enforced boundaries are also not free. Giving each module its own data means removing the joins and foreign keys that cross a boundary, which is real work in an existing system, and the check itself must be kept up to date. The alternative is a style where the boundary is a process and a network, which costs more and is the subject of the next lesson.
A monolith is one unit of deployment. Its parts call each other in-process, usually over one database, so one transaction can cover several of them.
Deployment unit and code structure are separate questions. A tangled system split into services is the worst cell: the coupling stays and a network is added.
A modular monolith keeps one deployable and adds modules with a public interface, their own data and a boundary that a tool checks. 5 modules have 20 ordered pairs, and a check can fail the build on each of the 14 that the design forbids.
It does not give independent release or independent scaling. A 40-minute serial pipeline allows 12 deploys in 8 hours, and a unit that is deployed together scales together: 16 GB for the example against 7 GB with the hot part on its own.
Without a check, the boundaries last as long as the team’s discipline.