Skip to content

Monolith, modular monolith and microservices

Every system must decide how to divide its code into deployable units: one application, a few, or hundreds of small services. The decision shapes how teams work, how the system fails and what it costs to run. The industry has swung from monoliths to microservices and partly back. The current consensus is less about fashion and more about matching boundaries to teams and to real scaling needs.

The first split in most systems is between the web tier, which handles HTTP, sessions, rendering and the public API surface, and the application or platform tier, which holds business logic and talks to data stores.

flowchart TB
  clients["Clients"] --> lb["Load balancer"]
  lb --> web1["Web server"]
  lb --> web2["Web server"]
  web1 & web2 --> app["Application tier:<br/>users, orders, search"]
  app --> db[("Databases")]
  app --> q["Queue"]
  q --> workers["Background workers"]

Why split:

  • Independent scaling. A new internal API or a heavy batch job adds application servers without adding web servers, and vice versa.
  • Reuse. Web, mobile and partner APIs can share one platform tier instead of each re-implementing the logic.
  • Team separation. Product teams iterate on the web layer while a platform team evolves the core.
  • Async work. Workers in the application tier take slow jobs off the request path through queues.

Single responsibility, from classes to services

Section titled “Single responsibility, from classes to services”

The single responsibility principle says a unit of code should have one reason to change. Applied to architecture, each module or service owns one business capability (billing, search, notifications) and its data, and exposes a narrow, stable interface. Good boundaries follow the business domain (domain-driven design calls them bounded contexts), not technical layers. A “database service” or a “validation service” is a sign of the wrong cut.

This principle does not require a network boundary. You can apply it inside one codebase, which is the whole idea of the modular monolith.

Microservices are an architecture in which an application is built as a set of small services that:

  • each run as their own process and are deployed independently;
  • each own their data. No other service reads their tables directly;
  • communicate over the network through well-defined APIs (HTTP/JSON, gRPC) or events;
  • are each owned by one team, end to end, including on-call.

A photo-sharing product might have services for user profiles, follow graph, feed, search, media upload and notifications, each with its own store and release cadence. “Micro” refers to scope (one capability), not to lines of code.

A modular monolith is one deployable application whose code is split into modules with explicit public interfaces and enforced dependency rules. Module A may call B’s public API but not touch B’s internals or tables. It keeps the operational simplicity of a monolith, with one build, one deploy, in-process calls and one database (with a schema or set of tables per module), while getting most of the design benefits of services.

Shopify is the best-known example. Its large Ruby on Rails monolith, worked on by more than a thousand developers, was reorganised into components by business domain, with tooling that flags calls bypassing a component’s public API. Microservices were considered and rejected because of their operational and latency costs.

To make modules real rather than folders:

  • enforce boundaries in CI with dependency rules, architecture tests or a tool such as Packwerk or ArchUnit;
  • give each module its own tables, and don’t join across module tables;
  • communicate through interfaces or in-process events, which can later become network calls or messages;
  • keep the build fast with module-level test suites.

A well-modularised monolith is also the easiest system to split later, because the seams already exist.

Microservices solve mostly organisational problems, and a few technical ones:

  • Many teams, one release train. Once dozens of teams share one deployable, merges, test suites and release coordination slow everyone down. Independent services let each team ship on its own schedule.
  • Conway’s law. Melvin Conway observed in 1968 that systems mirror the communication structure of the organisations that build them. Service boundaries that match team boundaries reduce coordination. Boundaries that cut across teams create constant cross-team negotiation. Some organisations design teams first and let the architecture follow (the “inverse Conway manoeuvre”).
  • Very different scaling profiles. A video transcoder needs GPUs and scales with uploads; the account service needs little. Separating them avoids scaling everything for the needs of one part.
  • Fault and security isolation. A memory leak in recommendations should not take down checkout. A PCI-scoped payment service can be locked down separately.
  • Technology fit. A part that genuinely needs a different language or runtime, such as an ML model server, can have one.

If none of these applies, the split mostly adds cost.

  • Network calls instead of function calls. Each hop adds latency (a few hundred microseconds within a zone, about a millisecond across zones, versus nanoseconds in-process) and can fail. A request that touches 10 services in sequence, each at 99.9% availability, succeeds only about 99.0% of the time, roughly 87 hours of failure a year instead of under 9.
  • Partial failure. Timeouts, retries, circuit breakers, idempotency and fallbacks become everyday code. See resilience patterns.
  • Distributed data. No cross-service transactions or joins. You need sagas or outbox-based events, accept eventual consistency, and duplicate some data for reads.
  • Operations. Dozens of pipelines, dashboards, alerts and on-call rotations; service discovery; distributed tracing and centralised logs (observability); version compatibility between services; a platform team to make it all bearable.
  • Testing and local development. Running the whole system on a laptop becomes hard. Contract tests and shared staging environments are needed.
  • Wrong boundaries are expensive. Moving a responsibility between services means API changes and data migrations, not a refactor in one repository. The worst outcome is a distributed monolith: services that must be deployed together and call each other synchronously for every request, with all the costs and none of the benefits.

Teams do move back. Twilio Segment merged more than 140 per-destination services into one service in 2018, and in 2023 a Prime Video monitoring team reported cutting infrastructure cost by over 90% by collapsing a distributed, serverless pipeline into a single process. Both are cases of boundaries drawn finer than the problem needed, not proof that services are wrong.

Big-bang rewrites usually fail: they take years, the old system keeps changing, and nobody fully knows what it does. The strangler fig pattern, named by Martin Fowler after a vine that slowly grows around its host tree, replaces a system piece by piece.

flowchart TB
  client["Clients"] --> facade["Routing facade:<br/>proxy or gateway"]
  facade -->|"/orders/*"| newsvc["New order service"]
  facade -->|"everything else"| legacy["Legacy monolith"]
  newsvc -.->|"sync data during transition"| legacy
  1. Put a routing layer, such as a reverse proxy or API gateway, in front of the legacy system.
  2. Pick one capability with a clear seam. Build it anew and route its traffic there, gradually, with a percentage rollout or shadow traffic to compare results.
  3. Keep data consistent during the transition with change data capture, dual writes through an outbox, or a temporary sync job.
  4. Delete the legacy code path once traffic is fully moved. Repeat.

The same pattern works for extracting a module from a modular monolith, or for moving between platforms.

Functions as a service such as AWS Lambda, Google Cloud Run functions, Azure Functions and Cloudflare Workers take the service idea further: you deploy functions, and the platform handles servers, scaling (including to zero) and per-invocation billing. Container platforms like Google Cloud Run and AWS Fargate offer a middle ground: serverless operations for ordinary long-running HTTP services.

Serverless fits event-driven glue (react to an upload, a queue message, a webhook), spiky or low-traffic workloads, and scheduled jobs. Watch for:

  • Cold starts on infrequently used functions (mitigated by provisioned concurrency or isolate-based runtimes);
  • Execution limits: a standard Lambda invocation still stops at 15 minutes. Since late 2025, durable functions checkpoint a workflow across many invocations for up to a year, and since September 2026 Lambda Managed Instances allow 90 minutes for asynchronous and most queue- or stream-triggered invocations;
  • Cost at high steady load, where always-on containers are often cheaper;
  • Downstream pressure: thousands of concurrent functions can exhaust database connections;
  • Fragmentation: hundreds of tiny functions are a distributed system that is hard to reason about.

Serverless is a deployment and billing model. The boundary questions above still apply.

MonolithModular monolithMicroservices
DeployablesOneOneMany, one per service
Module boundariesOften implicit, erode over timeExplicit, enforced by toolingEnforced by the network
Calls between partsIn-processIn-processNetwork (RPC, HTTP, events)
DataOne shared schemaOne database, tables owned per moduleDatabase per service
TransactionsLocal ACIDLocal ACIDSagas, outbox, eventual consistency
Independent deployNoNoYes
Independent scalingScale the whole appScale the whole appPer service
Fault isolationLowLow to mediumHigh, if designed for it
Operational overheadLowLowHigh: platform, tracing, discovery
Best fitSmall team, early productMost products, up to many teamsMany autonomous teams, very uneven scaling needs

Based on The System Design Primer by Donne Martin (CC BY 4.0). Restructured, rewritten and updated; site content is licensed under CC BY 4.0.