Skip to content
codmaker

Modular Monolith vs Microservices: When to Choose Each

Microservices add a tax most small teams can't afford. What a modular monolith is, how to enforce boundaries in a monorepo, and when splitting makes sense.

CodmakerUpdated 7 min read
Share

Why Teams Are Moving Back to Monoliths

For years, microservices were the default answer to 'how should we structure a serious app?'. Split everything, deploy independently, scale each piece on its own. It sounded like the grown-up choice.

My take: microservices are a complexity trap for most teams. They solve problems of organizations with many independent teams. If you are a small product team, you inherit the cost without the payoff.

The alternative isn't a big ball of mud. It's a modular monolith: one deployable app with hard internal boundaries. You get most of the structure people want from microservices, minus the network in between.

What Is the Microservice Tax?

The moment you split an app across a network, you sign up for a list of new problems. Network latency. Serialization costs on every call. Distributed tracing so you can follow one request across five services. Eventual consistency, because a single database transaction no longer covers the whole operation.

Each of these is solvable. None of them is free. For a team of five, the combined weight is a productivity killer. You spend your week on plumbing instead of on the product.

  • Latency: an in-process function call becomes an HTTP or queue round trip that can fail or time out.
  • Serialization: every boundary means encoding and decoding data, plus keeping schemas in sync.
  • Observability: you need tracing and correlated logs just to debug one user action.
  • Consistency: cross-service writes need sagas, outbox patterns or retries instead of one transaction.
  • Ops: more deploy pipelines, more config, more things to version and roll back.

What Is a Modular Monolith?

A modular monolith is a single application, deployed as one unit, that is split internally into modules with clear ownership and explicit public interfaces. Billing, auth, notifications and search each live in their own module. Each one exposes a small API and hides its internals.

The key idea: we can have boundaries without network calls. Modules talk through plain function calls and shared types. You still get separation of concerns. You don't pay for it in latency or partial failures.

Done right, a modular monolith also keeps the door open. If one module later needs to become its own service, its boundary already exists. Extracting it is a refactor, not a rewrite.

How to Enforce Module Boundaries in a Monorepo

Boundaries only matter if something enforces them. Good intentions decay the first time someone is in a hurry and imports a private helper from another module.

This is where monorepo tooling earns its keep. With Nx or Turborepo you split the codebase into packages and set rules about who can depend on whom. For example, 'billing' cannot import 'auth' internals directly. It has to go through the public interface auth exposes. Nx ships a lint rule for module boundaries based on project tags. In a Turborepo setup, the usual approach is separate workspace packages plus ESLint import restrictions.

Everything still ships as a single deployable unit. In a Next.js project, that often means one app package that composes feature packages, each with its own index file as the only allowed entry point.

  • Give each module one public entry point and treat everything else as private.
  • Make dependency rules fail CI, not just show a warning in the editor.
  • Keep shared code in a small, boring package (types, utilities), not a dumping ground.
  • Let each module own its own tables or schema, even inside one database.

Modular Monolith vs Microservices: Key Differences

Both approaches care about boundaries. The difference is where the boundary lives and what it costs to cross it.

In a modular monolith, crossing a boundary is a function call. Refactoring across modules is a single pull request with type checking on both sides. Deploys are one pipeline. Local development is one command.

With microservices, crossing a boundary is a network call. Changing a contract means versioning, coordinated deploys or backward compatibility shims. In return, each service can deploy, scale and fail on its own schedule, and different teams can pick different stacks.

That independence is the real product microservices sell. If you don't need it, you are buying it anyway.

When Do Microservices Actually Make Sense?

Microservices aren't wrong. They are a tool for specific problems, mostly organizational ones. Reach for them when the pain of one deploy unit is bigger than the pain of the network.

  • Many teams need to ship independently and keep blocking each other in one codebase.
  • One part of the system has very different scaling needs, like a heavy media or AI processing worker.
  • A component needs a different runtime or language for a solid technical reason.
  • Strict isolation is required for security or compliance on a specific piece of data.

Common Mistakes With Modular Monoliths

The biggest mistake is calling something a modular monolith when it's just a monolith with folders. Folders are not boundaries. If any file can import any other file, you have no modules.

The second mistake is a shared database free-for-all. If billing queries auth's tables directly, the modules are coupled at the data layer no matter how clean the code looks.

The third is splitting too early in the other direction. Teams extract a service on day one 'because we'll need it later'. Start with a module. Extract it when you have a concrete reason, like independent scaling or a separate team that owns it.

Frequently Asked Questions

Is a modular monolith better than microservices?

For small and mid-sized teams, usually yes. You get clear boundaries without network latency, distributed tracing or eventual consistency. Microservices pay off when many teams need to deploy independently or parts of the system scale very differently.

What is the difference between a monolith and a modular monolith?

Both deploy as one unit. A plain monolith has no enforced internal structure, so any code can depend on any other code. A modular monolith splits the app into modules with public interfaces and enforces those boundaries with tooling.

Can you migrate from a modular monolith to microservices later?

Yes, and that's one of its main advantages. If a module already has a clean public interface and owns its own data, extracting it into a service is mostly about putting a network API in front of that interface.

Can Nx or Turborepo enforce module boundaries?

Nx has a built-in lint rule that restricts dependencies between projects based on tags. With Turborepo, teams usually split code into workspace packages and add ESLint import rules so modules can only use each other's public entry points.

Does a modular monolith work with Next.js?

Yes. A common setup is a monorepo with one Next.js app that composes feature packages like billing, auth and dashboard. Each package exposes a single entry point, and the app deploys as one unit.

Written by Codmaker

An independent product lab. We build and run our own React Native and Next.js apps, and write up what we learn along the way.

See our apps
All guides →
React8 min read

React Compiler: Do You Still Need useMemo?

What the React Compiler does, how to turn it on in Next.js, when useMemo and useCallback still matter, and the mistakes that stop it from optimizing your code.

Next.js10 min read

Next.js Server Actions: A Practical Guide

What Next.js Server Actions are, how to use them with forms, how to validate and secure them, and when an API route is still the better choice for the job.