Skip to content
nexovia
All insights

Architecture

Microservices vs monolith: match your services to your team size

The number of services you run should follow the teams that can own them and the parts that really must deploy and scale on their own. That points to a modular monolith on some products and to microservices on others.

The Nexovia team · · 5 min read

Microservices and monoliths solve different problems

The microservices vs monolith question is usually argued as if one of them were the modern answer. Neither is. Microservices exist so that several teams can build, deploy and scale their parts of a product without waiting for each other. A modular monolith exists so that a product can keep strict internal boundaries while being built, tested and deployed as one unit.

Which problem you have depends on the project, so we look at it before choosing. The first limit is people: a service needs someone who deploys it, monitors it and gets woken up when it fails, and five developers cannot do that for twelve services and still ship features. The other criteria are deployment, scaling, runtimes and compliance, covered below.

What a modular monolith looks like, and where it strains

A modular monolith is one codebase and one deployable, split into modules with boundaries as strict as those between services. Billing, catalog and notifications are separate modules. A call between them is a function call inside one process and one database transaction, with no network in between. The boundaries only hold if they are rules, not intentions:

  • Each module exposes a small public interface and owns its tables. No other module queries or joins them directly.
  • Modules talk through the public interface or through domain events, never by reaching into each other's internal models.
  • The rules are checked automatically in CI: Deptrac or Pest architecture tests in PHP, dependency-cruiser or lint rules in TypeScript, ArchUnit in Java.
  • Where it strains: every change ships in the same deploy, one bad release can take down the whole application, every module runs on the same runtime, and the full test suite grows with the codebase. Several teams sharing one release train start to wait for each other.

What microservices cost to operate

Splitting a system into services turns function calls into network calls, and that changes everything downstream. Every call can now time out, arrive twice or fail halfway through. This is a bill, and it is worth paying when it buys something you need. The main items on it:

  • Each service needs its own pipeline, deployment, dashboards, alerts and on-call knowledge.
  • There are no transactions across services. You design for eventual consistency, with retries, idempotent handlers and patterns such as the outbox.
  • Debugging one request means following it through several services, which requires distributed tracing and correlated logs.
  • APIs between services must be versioned, because the two sides no longer deploy together.
  • A developer needs a large part of the system running locally to test one feature.

Signals that call for separate services

"It will be cleaner" is not one of them: clean boundaries are available inside a monolith, and several copies of a stateless monolith behind a load balancer handle a lot of traffic. These are the signals we look for, on a new product as much as on an existing one:

  • Independent teams. Separate teams own separate areas, each with its own roadmap, and a shared deploy would make them wait for each other.
  • Independent scaling. One workload has a load profile unlike the rest, such as video processing, a WebSocket gateway or a heavy import job, and scaling the whole application to serve it is wasteful.
  • A different runtime. The work needs a tool the main stack is weak at: Node for long-lived connections, Python for machine learning, a headless browser for rendering.
  • A different release cadence. One part changes several times a day while another must move slowly and be validated before each release.
  • A compliance or security boundary. Card data kept in a separate service, with its own database and network access, limits the part of the system a PCI DSS assessment covers, and medical or other sensitive records can be isolated the same way.

Matching the architecture to the team, in both directions

When several of these signals are present from the first day, for example separate teams, a Python component and a payment service that must stay isolated, starting with services is the sound choice, provided the boundaries are already understood. When none of them is present, a modular monolith gives the same boundaries for less work. Many products sit somewhere between: a modular core with one or two services kept apart for a specific reason.

The right answer also changes over time. We have merged microservices back into a modular monolith when the team was too small to run them, and kept apart only the services that ran on a different runtime. The reverse move is just as legitimate: when new teams join or one module needs its own scaling, splitting it out is the right call. In both cases the trigger is a change in the team or the load, not a change in fashion.

Changing course without building a distributed monolith

Extracting a service from a modular monolith is cheap when the module already has a public interface and owns its data. Extraction means replacing in-process calls with an HTTP API or a message queue, moving the module's tables to their own database, and giving the new service its own pipeline and monitoring. Do it one service at a time, for a reason from the list above, and check afterward that the problem went away.

Merging works the same way in reverse: bring one service into the monolith as a module, keep its interface, replace the network calls with function calls, and fold its tables into the main database once nothing else reads them. What goes wrong in either direction is splitting before the boundaries are known. That produces a distributed monolith: services that must be deployed together and fail together, with the costs of both models. We record each of these decisions, with its reason, in an architecture decision record in the repository.

Keep reading

Design, build and ship your project

Describe it in three lines. We reply with specific questions and a first take on how to proceed.