Monolith, modular monolith or microservices
Microservices let teams ship on their own, but every network call has a cost. Learn what each style buys, what it costs, and why a modular monolith is often the best start.
Updated since you finished it. We changed this lesson after you marked it done. Your progress is kept.
What broke
This story is made up, but the pattern is common.
A shop has one large app and 40 engineers. Deploys queue up, and one team's bug can block everyone's release. So the company decides to "move to microservices". In six months, the app becomes nine services.
But the services still read and write the same database tables. A new checkout feature needs changes in five services. The five teams must deploy them in the right order, on the same night.
Then a customer is charged, but gets no order. The request crossed four services. Each one has its own logs, and nothing ties them together. It takes two days to find a timeout between two of them.
The team kept the old pain, the shared release. They added new pain: network calls, partial failures and lost traces. They split the code, but not the ownership or the data.
The idea in simple words
A monolith is one application that you build and deploy as one unit. Lewis and Fowler point to two limits. Change cycles are tied together, so a small change means you build and deploy the whole app. And you must scale the whole app, not just the part that needs more resources. 1
Microservices build one application as a set of small services. 1 Each service can be deployed and scaled on its own. 1
A modular monolith sits between them. Shopify describes it as one application in which "there are strictly enforced boundaries between different domains". 6 You get clear parts, but still one deploy.
The key idea. Microservices mostly buy independence for teams: each team deploys and scales its part on its own. You pay for it with network calls, data spread across databases and more to run. Pay only when the independence is worth more than the cost.
How it works
What microservices cost
Step through one order request in both styles. Use Next and Back, or the ← and → keys.
- In a modular monolith, an order request reaches the Orders module. It calls Stock, Payments and Email as plain function calls, inside one process, with one database.
- All the writes go in one database transaction. If the payment fails, the stock change rolls back too. A stack trace shows the whole path.
- Now the same request with four services. Orders must call Stock, Payments and Email over the network. Each call adds a hop, and its own wait.
- Any hop can fail or time out. If the charge call times out, Orders does not know if the card was charged. It needs timeouts, retries and idempotency keys.
- Each service owns its database, so there is no single transaction. To undo the stock hold, you need a saga. To see the whole path, you need distributed tracing.
Network calls. A function call in memory becomes a request over the network. Shopify lists this as one reason they did not pick microservices. Network calls add latency and reduce reliability. 6 Lewis and Fowler say services must be designed to cope when other services fail. 1 So every call needs a timeout, retries and idempotency.
Data and transactions. Each service usually owns its data. Lewis and Fowler write that distributed transactions "are notoriously difficult to implement". So microservice systems tend to accept eventual consistency and fix problems with compensating operations. 1 In practice, that means sagas, outbox and CDC.
Running it. Fowler calls this the "microservice premium". The style adds cost and risk that "often gets projects into serious trouble". You need deployment automation, monitoring, failure handling and a way to deal with eventual consistency. 3 Shopify also lists a test and deploy pipeline for each service, and infrastructure for each one. Large changes across services need coordinated deploys. 6
To follow one request across services, you also need good observability, with traces that cross every hop.
Conway's law
In 1968, Melvin Conway argued that organisations which design systems are "constrained to produce designs which are copies of the communication structures of these organizations". 5 This is Conway's law. Lewis and Fowler give an example. When teams are split by technical layer, such as UI, server and database, even simple changes become projects across teams. They call this "Conway's Law in action". Their answer is cross-functional teams and services organised around business capabilities. 1
Our advice: draw the team chart next to the service map. If one team owns six services, it gets all the costs and little of the independence. If one service needs three teams to change it, its boundary is wrong. The lesson on team topologies and Conway's law goes deeper.
The modular monolith: a common middle path
Shopify runs "one of the largest Ruby on Rails codebases in existence". More than a thousand developers have worked on it for over a decade. 6 They judged that microservices "would bring their own set of challenges". 6
So they kept one app and changed how the code was organised. They moved from folders by software type (models, views, controllers) to components by business area, such as orders, shipping, inventory and billing. 6 A tool records the calls made while tests run in CI. An internal tool called Wedge uses this data to flag calls that cross component boundaries. Calls are allowed only to things a component makes public. 6
Fowler gives the same default. Do not even consider microservices unless the system is too complex to manage as a monolith. Build most systems as one application with good internal modularity. 3
Monolith first, then the strangler fig
Fowler noticed that "almost all the successful microservice stories have started with a monolith that got too big and was broken up". Systems built as microservices from scratch often "ended up in serious trouble". 2 One reason: even experienced architects find it hard to get boundaries right at the start. 2 He also notes that this view is not shared by everyone. 2
When it is time to split, do not rewrite everything at once. Fowler's strangler fig approach grows the new system around the old one. You add new parts next to the old code, then move behaviour across one piece at a time. 4 Each step is small, so the risk is lower and value arrives sooner. 4 Sam Newman's book covers this pattern, and how to split the database when you break up a monolith. It also asks a harder question: should you migrate at all? 9
Going back is allowed
In 2023, a Prime Video team wrote about a monitoring service built from distributed serverless parts. The way the team used some components hit a hard scaling limit at about 5% of the expected load. Its orchestration and the data passed between parts cost the most. 7 The team moved all the parts into one process, so data moved in memory. The infrastructure cost of this one service fell by over 90%. 7 The post adds that the choice between microservices and a monolith "has to be made on a case-by-case basis". 7
Segment had over 140 small services. Three full-time engineers spent most of their time keeping the system running. 8 They merged the services into one. Deploys and tests became much faster. 8 The post is honest about the cost: one bad part can now crash the whole service. 8
When to split, and signs you split too early
Our rules for when one part should become its own service:
- A separate team owns it, and the shared release truly blocks that team.
- It needs very different scaling, hardware or reliability from the rest.
- Its boundary is already clean inside the modular monolith, with few calls across it.
Signs you split too early:
- Most features change several services, which must deploy together.
- Services share database tables.
- You have more services than teams.
- Nobody can follow one request from end to end.
Trade-offs
| Option | Independent deploys? | Main cost | Use it when |
|---|---|---|---|
| Monolith | No Change cycles are tied together. 1 | Shared release. You scale all of it. 1 | A small team, a new product, a domain still being learned. |
| Modular monolith | No , but teams work in clear parts. 6 | You must check the boundaries, for example with a CI tool. 6 | The default for most growing teams. |
| Microservices | Yes Each can deploy and scale on its own. 1 | Network calls, no shared transactions, more to run. 3 6 | Many teams that block each other, or parts with very different needs. |
| Services with shared tables and lockstep deploys | No | All the costs of microservices, with few of the gains. | Never on purpose. Merge back or fix the boundary. |
At work: how a senior uses this
- When someone says "let's use microservices", ask: "Which team will deploy on its own because of this, and what does it stop waiting for?"
- Start with a modular monolith. Make each module own its tables, and check the boundaries in CI.
- Before you extract a service, count the calls across that boundary. If it is chatty, it is not ready.
- Split one service at a time, with the strangler fig approach. Keep a way to send traffic back.
- Give each service one owning team. More services than teams is a warning.
- Budget the premium: tracing, dashboards, on-call, a pipeline for each service, and a plan for data that crosses services.
With AI
What to ask the agent
"Here is our module list and the calls between modules from the last month. Group modules that call each other a lot. Suggest boundaries where cross-module calls are rare."
"We want to extract the Payments module into a service. List every database table it reads or writes that other modules also use, and every call into it. What must change first?"
"Act as a skeptical staff engineer. Argue against splitting this app into services. What new failures and costs would we take on?"
What to check yourself
- The call data is real, from traces or code analysis, not guessed by the agent.
- Every table in the split plan has one owner. No two services write the same table.
- Every new network call has a timeout, a retry rule and an idempotency key where it changes data.
- The plan says which team owns each new service, and who is on call for it.
- Claims about a tool's limits come from its official docs.
Check yourself
Your progress is saved only in this browser. Export it to keep it safe.
You have finished 5 lessons. Your progress lives only in this browser. Export a copy so you don’t lose it.
Go deeper
Show 9 sources and related lessons
- James Lewis and Martin Fowler, “Microservices” (martinfowler.com, March 2014) (opens in a new tab)
The common definition of the style, the comparison with a monolith, Conway's law, decentralised data and design for failure. - Martin Fowler, “MonolithFirst” (June 2015) (opens in a new tab)
Why most successful microservice stories began as a monolith, and why boundaries are hard to get right early. - Martin Fowler, “Strangler Fig” (August 2024 version) (opens in a new tab)
How to replace an old system bit by bit instead of in one big rewrite. - Melvin E. Conway, “How Do Committees Invent?”, Datamation, April 1968 (opens in a new tab)
The original paper behind Conway's law. The main claim is in the conclusion. - Kirsten Westeinde, “Deconstructing the Monolith: Designing Software that Maximizes Developer Productivity”, Shopify Engineering (February 2019) (opens in a new tab)
Why Shopify chose a modular monolith over microservices, how they split the code, and the Wedge tool that checks boundaries. - Marcin Kolny, “Scaling up the Prime Video audio/video monitoring service and reducing costs by 90%”, Prime Video Tech (March 2023, archived copy) (opens in a new tab)
One team moved a service from distributed serverless parts into one process, and cut its infrastructure cost by over 90%. - Alexandra Noonan, “Goodbye Microservices: From 100s of problem children to 1 superstar”, Segment (July 2018) (opens in a new tab)
Segment merged over 140 small services back into one, and lists what got better and what got worse. - Sam Newman, “Monolith to Microservices” (O'Reilly), book page (opens in a new tab)
A book on whether to migrate at all, migration patterns such as the strangler fig, and splitting the database.
Case studies: Shopify: Choosing a modular monolith over microservices · Swiggy: Turning a delivery monolith into a logistics platform
Related: Domain-driven design · Team Topologies and Conway's law (coming soon) · Sagas, outbox and CDC · Evolutionary architecture and the strangler fig (coming soon) · Making architecture trade-offs · Observability, SLOs and error budgets
Before this: domain-driven design. Next: evolutionary architecture and the strangler fig, sagas, outbox and CDC, and making architecture trade-offs.