Nguyen Le Phong

Foundations of Software ArchitecturePart 5 of 15

When to Split a Monolith Into Microservices (and When to Wait)

Most teams should start with a monolith, enforce module boundaries next, and split out services only when team or scaling pain is real.

Say a three-person startup decides on day one that it'll run on microservices. Six months in, there are fifteen services, a Kafka cluster nobody fully understands, and a checkout bug you can only reproduce by following one request through eight of them. The product is half done. Then someone in Slack types the line every architect dreads: "so we built a distributed monolith."

A small team gathers around screens showing an abstract service map, trying to follow one bug across many boxes.
Splitting early rarely looks wrong on day one. The bill shows up later, one cross-service bug at a time.

Microservices are a real tool, and at the right size they solve real problems. They also cost a lot to run, and that cost lands well before the benefits do. Martin Fowler calls it the microservice premium: extra cost and risk you take on for deployment automation, monitoring, failure handling and eventual consistency. This post walks through the three shapes most systems pass through (monolith, modular monolith, microservices), what each one is good at, and the signals that say it's time to move on. If you mostly care about the running costs, The Real Bill for Microservices, Line by Line goes deeper on that side.

The monolith is a fine place to start

A monolith is one deployable unit. One build, one artifact, one deploy step. Every feature and every query runs in the same process, usually against one database.

The word has picked up a slightly embarrassing ring, as if having a monolith means you've fallen behind. Fowler's experience points the other way. In Monolith First (2015) he wrote that almost all the successful microservice stories he'd heard began with a monolith that got too big and was broken up, and that almost every system he'd heard of that was built as microservices from scratch ended up in serious trouble.

A few reasons a monolith is easy to live with early on:

  • Calls stay in memory. A function call doesn't time out, return half an answer or get lost on the network. A call between services can do all three.
  • Transactions stay boring. Moving money from account A to account B is one database transaction. Split across two services, it becomes a saga with compensating steps (the saga post shows what that takes).
  • Debugging happens in one place: one process, one log stream, one stack trace.
  • Deploys are simple: one pipeline and one way to roll back.
  • It scales further than its reputation. In 2016, Stack Overflow's Nick Craver reported 209 million HTTP requests in a single day, running on 11 web servers (9 of them serving production) and 4 SQL Servers, with one multi-tenant application handling all the Q&A sites (Stack Overflow: The Architecture, 2016 Edition).

The pains do come, just later. Builds and test runs slow down as the code grows. Twenty people editing the same codebase means more merge conflicts. Everyone ships on the same release train, so one risky change can hold up everybody else. Those are the problems of a product that's growing, and plenty of teams never get to the point where they hurt badly.

The modular monolith, the step most teams skip

A modular monolith still deploys as one unit. Inside, the code is split into modules with boundaries the build actually checks. Modules talk through a small public interface. Nobody imports another module's private classes, reads its tables or calls its internal helpers.

Think of a studio apartment next to a flat with proper rooms. Same front door, same plumbing, one address. The kitchen and the bedroom just have a wall between them, and nobody cooks on the bed.

A team arranges colored module blocks inside one shared system model, with clear lines between the blocks.
Still one deployable, now with walls. Each module can be read, reviewed and changed on its own.

Good modules follow the business: billing, inventory, notifications. In Domain-Driven Design terms, each one sits close to a bounded context, a part of the system where one model and one vocabulary hold. A module owns its logic and its part of the schema, exposes a small API and keeps everything else private.

Shopify is the best-known example. Its Rails codebase had been worked on for over a decade by more than a thousand developers when the team weighed microservices and passed, because services would bring several test and deploy pipelines plus network latency. They reorganized the code by domain (orders, shipping, inventory, billing) and built a tool called Wedge that traces calls during CI and flags any call that crosses a component boundary without going through a public interface (Deconstructing the Monolith, 2019). They later open-sourced Packwerk for the same job.

You don't need custom tooling to start. In a TypeScript codebase, one lint rule blocks deep imports into another module's internals:

// eslint.config.js
export default [
  {
    rules: {
      'no-restricted-imports': ['error', {
        patterns: [{
          group: ['**/modules/*/internal/**'],
          message: "Import from the module's index file instead.",
        }],
      }],
    },
  },
]

What that discipline buys you:

  • You can work on billing without holding the whole codebase in your head.
  • You can rewrite a module's internals freely, as long as its public API stays put.
  • Ownership is obvious. A new hire learns one module first instead of the entire repo.
  • The seams are already drawn. If you ever extract a service, the module becomes the service and its interface becomes the API. Still real work, but you know where to cut.

Fowler's premium article says it plainly: most systems should be built as a single application, with good modularity inside it. A modular monolith is what that advice looks like in a real repo.

What microservices actually buy you

Microservices split the system into services that deploy independently. Each one runs in its own process, has its own pipeline and, most importantly, owns its own data. James Lewis and Martin Fowler's 2014 article describes services organized around business capabilities, each managing its own database and built to cope when other services fail.

When it works, you get four things:

  • Independent deploys. The payments team ships on Tuesday afternoon without waiting for search or notifications.
  • Independent scaling. If image processing needs forty cores at peak and user profiles need two, you scale them separately.
  • Team autonomy. A team of five can own a service end to end, from code to on-call. Conway's law says a system ends up copying the communication structure of the organization that builds it (Mel Conway, 1968). Microservices let you plan for that on purpose.
  • Fault isolation. A memory leak in recommendations takes down recommendations, and checkout keeps working. That only holds if checkout doesn't sit waiting on recommendations synchronously.

Look at that list: every item is about many teams and uneven load. A team of eight still looking for product-market fit doesn't have those problems yet.

The bill that comes with them

Each benefit has a matching cost:

  • Network calls fail. They time out, return stale data, or succeed on a retry after the first attempt already had side effects. You handle partial failure everywhere.
  • Data drifts apart. Each service owns its data, so keeping it consistent takes events, idempotent handlers, sagas and usually an outbox. Someone also gets to explain to the PM why a new order takes a moment to show up in order history.
  • Queries get harder. Chris Richardson's Database per Service pattern lists the two big drawbacks right away: business transactions that span services, and queries that join data now living in several databases.
  • Debugging needs new gear. A stack trace stops at the process edge. You need distributed tracing, correlation IDs in every log line and dashboards that look across services (more in Observability Is a Design Decision).
  • Ops work multiplies. Every service needs an image, deploy config, health checks, resource limits, log shipping and alerts. Thirty services means thirty of each.
  • Integration tests get heavier. Testing across services means running several of them with the right versions and the right data. Contract tests help, and they're one more thing to learn.

Fowler's Microservice Prerequisites sets a floor before you start: you can fire up a new server in a matter of hours, you have monitoring that catches serious problems quickly, and you can deploy fast to both test and production. If one of those is missing, extra services will hurt before they help.

Watch out for the distributed monolith

The worst place to land is a set of services that must deploy together, share one database or fail together. You pay every cost above and get none of the benefits. It usually happens when teams split by technical layer (a "database service", a "validation service") or when services call each other in long synchronous chains. Quick test: if ServiceA can only ship after ServiceB, you've built one.

Engineers study tracing dashboards on several monitors while chasing one failure across services.
One click from a user can turn into a trace across a dozen network hops, and every hop is a place to fail.

Signs it's time to split, and signs it isn't

Splitting starts to pay off when you can point at a concrete pain. Good signals:

  • One component needs very different resources from the rest, and scaling the whole monolith for its sake costs real money.
  • Deploy contention is a weekly thing. Teams regularly wait on other teams' changes before they can ship.
  • Several teams work on separate business domains, each with its own roadmap and release rhythm.
  • A component has different security or compliance needs. Payments, auth and personal data often deserve their own blast radius and their own audit trail.
  • A module is already separate in practice: no shared tables, talks to the rest only through an API or events, owned by a different team. Turning it into a service just writes down what's already true.

Signs you're early:

  • The reason is "it feels more scalable," with no limit you've actually hit.
  • The services you're planning would have to deploy together to work.
  • You can't yet draw boundaries where each service owns its data and no tables are shared.
  • You don't have the tracing, central logging and alerting to debug a distributed system.
  • If you're honest, the main reason is that "microservices" looks good in the job ad.

How to split without regretting it

Once the signals are there, how you split matters as much as whether you split.

Split by business capability. Skip DatabaseService and ValidationService, those are technical layers. Go for orders, billing, inventory: parts of the business with a stable meaning. Fowler's case for starting with a monolith rests on exactly this. Services only work with good, stable boundaries, and moving functionality between services is much harder than moving it around inside one codebase.

Use a strangler fig. Fowler named the pattern after vines he saw in the Queensland rainforest in 2001, which grow around a host tree and slowly replace it (Strangler Fig Application). You put the new service next to the monolith, route one slice of traffic to it, check it behaves, then delete that code from the monolith. The monolith shrinks over time, and you never stop the world for a rewrite. Sam Newman's Monolith to Microservices covers this and its cousins (branch by abstraction, parallel run, change data capture) in depth.

Extract one service at a time. The first extraction shows you how your deploys, tracing and data sync really behave. The second goes smoother. Doing five at once spreads the learning thin and stacks the risk.

Give every service its own data. A service that reads another service's tables is a module with network latency bolted on. Richardson's pattern points out you don't need a separate database server for this: private tables or a private schema per service, locked down with separate database users, already does the job. When two services need the same data, one owns it and the other asks through an API or keeps a copy fed by events.

Draw ports before you extract. If modules already talk through ports and adapters, extraction is mostly swapping an in-process adapter for an HTTP or gRPC client. The domain logic stays the same. It's one of the best practical reasons to use ports in the first place.

Side by side

Dimension Monolith Modular monolith Microservices
Deploy unit One process, one pipeline One process, one pipeline Many processes, each with its own pipeline
Data ownership One database; any code can touch any table One database; each module owns its tables, enforced by tooling Each service owns its data; no shared tables
When something crashes The whole app goes down The whole app goes down Other services keep running, if callers handle the failure
Team fit One or a few teams; friction grows with each new team Several teams, each owning modules Many teams that need to ship on their own schedule
Operational cost Low: one deploy, one log stream, one set of alerts Low: same footprint as a plain monolith High: tracing, orchestration, per-service CI/CD, sometimes a service mesh
Transactions Plain ACID transactions Plain ACID transactions Sagas and eventual consistency
Good fit when New product, small team, domain still unclear Growing product with clear domain boundaries Several autonomous teams, stable domain model, real uneven scaling needs

A rough map by stage

Most architecture advice comes from companies that already moved to microservices, because they're the ones with engineering blogs and conference slots. That skews what you read. Here's a rough map by product stage:

Three stages from left to right: a monolith, a modular monolith with internal boundaries, and separate microservices that each own a database. STAGE 1 STAGE 2 STAGE 3 Monolith One deployable All code one process shared DB enforce boundaries Modular Monolith One deployable · internal modules Billing Orders Notif. shared DB · owned schemas split at seams Billing Orders Notif. own DBs · network calls
Three stages. Left: one box with all the code together. Middle: still one box, with enforced module boundaries (dashed lines). Right: separate services, each with its own database, talking over the network (dashed arrows). You can stop at any stage. Pick the one your team and your load call for.

Early product: build a monolith. You don't know yet which parts need to scale, which features will survive or where the real domain boundaries sit. Splitting now locks in guesses. Shopify, still one Rails codebase after a decade and a thousand developers, shows how far a well-kept monolith can go.

Growing product, several teams: this is where the modular monolith earns its keep. One codebase without walls starts to hurt, while full microservices would slow everyone down. Invest in module boundaries, ownership and clean interfaces. Keep the option to extract a service, and use it only when a concrete need forces your hand.

Large org, many autonomous teams: selective microservices make sense here. Setups that hold up tend to be a mix: services for the parts with the heaviest load or the strictest rules, a modular core for the rest, and new services extracted one at a time as each seam proves itself.

What the big-company talks leave out

Conference talks show the diagram with hundreds of services. They rarely dwell on the starting point, and Fowler's observation covers it: almost every successful microservice story began as a monolith that got too big. Those companies are showing you where they arrived after years of work and tooling. Where you should start is a different question.

Try this week

  • Write down the one concrete pain splitting would solve. If you can't name it, stay put.
  • Pick one module and list every place outside it that imports its internals. That list is your first boundary to fix.
  • Add one lint or CI rule that blocks deep imports across modules.
  • Check Fowler's three prerequisites: a new server in hours, monitoring that catches serious problems, fast deploys. Fix the weakest one first.
  • If you do split, pick one bounded context with its own data and run it next to the monolith, strangler-fig style.

Once the backend is split, the next question is usually whether the frontend should follow. When Micro-Frontends Are Worth It (and What You Pay) picks up from there.

What did you think?

Frequently asked questions

Should a new project start with microservices?
Usually not. Martin Fowler's Monolith First notes that almost all successful microservice stories he heard of began as a monolith that grew too big, while systems built as microservices from scratch mostly ran into serious trouble. Start with a well-modularized monolith and split once you know where the stable boundaries are.
What is a modular monolith?
It's a single deployable application whose code is split into modules with enforced boundaries. Modules talk through small public APIs and never reach into each other's internals or tables. Shopify runs its large Rails codebase this way and checks the boundaries in CI.
When is it time to split a monolith?
When you can name a concrete pain: one component needs very different resources, teams regularly wait on each other to deploy, several teams own separate domains, or a component has its own security or compliance needs. "It feels more scalable" is not enough.
What is a distributed monolith?
A set of services that must deploy together, share a database or fail together. You pay all the costs of microservices and get none of the benefits. It usually comes from splitting by technical layer or from long chains of synchronous calls.
Does every microservice need its own database server?
No. Each service must own its data, but Chris Richardson's Database per Service pattern says private tables or a private schema per service, enforced with separate database users, is enough. A separate server mainly helps high-throughput services.