Course contents

10. Software Architecture Lesson 10 of 10

Architecture Trade-offs

Monolith, modular monolith or microservices? Compare hop counts and latency, failure blast radius, team autonomy and operational cost, and when to extract.

15 minIntermediate8 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • In-process calls are fast and fail together; network calls are slower and fail separately.
  • A modular monolith gets clear boundaries and owned data at no runtime cost, but keeps one deployment and one blast radius.
  • Microservices isolate failures only for paths that do not synchronously depend on the failed service.
  • Independent deployment and scaling per team are the main benefits of services; operations, tracing and consistency work are the price.
  • Start modular and extract a service when a real force (team blocking, scaling, availability) appears.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

Three common ways to structure a backend:

  • Monolith: one deployable unit, usually one database; components call each other in-process.
  • Modular monolith: still one deployable unit, but split into modules along business boundaries, each with its own data (schema) and a small public interface, enforced by the build.
  • Microservices: each module runs as its own service with its own database, deployed independently and called over the network.

Choosing between them is a trade-off across latency, failure isolation, team autonomy and operational cost. No option wins on every axis.

Why it exists

Teams often pick an architecture by fashion: microservices because large companies use them, or a monolith because it is the default. Both choices have real costs that show up later: a tangled monolith slows every team, and a premature microservices split adds hops, outages and an operations bill for benefits the organisation does not need yet. Naming the forces explicitly lets you pick deliberately and revisit the decision when they change.

How it works

Latency. A function call costs nanoseconds to microseconds. A call between services costs a network round trip plus serialisation, TLS and often a sidecar proxy: typically somewhere between a fraction of a millisecond and several milliseconds inside one data centre, more across zones. On a synchronous path these add up, and each extra service adds its own queueing, so tail latency grows faster than the median. In the lesson's model a checkout goes from one internal hop to four and its P95 rises by more than half.

Blast radius. Components in one process share memory, threads and fate: a leak or crash in one module takes down everything, which is equally true of a modular monolith. Separate processes fail separately, but a request still fails if its path makes a synchronous call to the failed service. Isolation therefore follows the dependency graph: asynchronous messaging, timeouts, circuit breakers and fallbacks are what turn separate processes into contained failures.

Team autonomy. A modular monolith gives each team ownership of a module and its data, but everyone ships in the same release. Services let each team build, test, deploy and scale on its own schedule, and pick technology per service where that is justified. This is the main reason large organisations use them (Conway's law in reverse).

Operational cost. Each service brings a pipeline, a runtime, a database with backups and migrations, dashboards, alerts and on-call. Across services you need service discovery, an API gateway, versioned contracts, distributed tracing, and patterns for consistency without distributed transactions (sagas, outbox, idempotent consumers).

Monolith Modular monolith Microservices
Internal call latency Lowest Lowest Network per hop
Failure blast radius Whole app Whole app Per service, along sync dependencies
Boundaries enforced By discipline By the build By the network
Deployment One, together One, together Independent per service
Scaling Whole app Whole app Per service
Data consistency Local transactions Local transactions (per module schema) Eventual between services
Operational cost Low Low High, grows with service count

In .NET, a modular monolith is typically one ASP.NET Core host composed of module projects, each registering its own services and its own DbContext on a separate schema, communicating through public contracts or in-process messages; architecture tests (e.g. NetArchTest or ArchUnitNET) keep modules from referencing each other's internals. Extracting a module later means moving the project behind an HTTP/gRPC API or a message broker, with its data already separate.

When to use it

  • Monolith: small teams, early products, simple domains, tight latency budgets.
  • Modular monolith: most new systems with more than one team or a domain still being discovered; the default good starting point.
  • Microservices: several teams blocked by shared releases, components with very different scaling or availability requirements, or organisations with the platform maturity (CI/CD, observability, on-call) to run many services.

When not to

  • Microservices with one team, an unclear domain or no platform support: you pay the distribution tax without the autonomy benefit.
  • A monolith without internal boundaries once several teams work in it: coupling makes every change slower.
  • Splitting by technical layer (a "database service", a "validation service") instead of business capability: it maximises hops and coupling.

Trade-offs

Choice You gain You pay
Modules instead of services No hops, local transactions, cheap refactoring of boundaries One deployment, shared blast radius
Services instead of modules Independent deployment, scaling, fault isolation Latency per hop, eventual consistency, operations
Synchronous calls between services Simple request/response semantics Availability and latency couple along the chain
Asynchronous messaging between services Failure and time isolation Eventual consistency, harder debugging
Fewer, larger services Fewer hops and contracts Less autonomy per team

Alternatives

  • Serverless functions: very fine-grained deployment units; same distribution costs, plus cold starts and platform limits.
  • Macro-services / "right-sized services": a few services aligned with team boundaries rather than one per entity.
  • Self-contained systems: vertical slices including UI, each owning its data, integrated mostly asynchronously.
  • Strangler fig migration: incrementally route functionality from a legacy monolith to new services or modules.

Failure modes

  • Distributed monolith. Services that must be deployed together and call each other synchronously everywhere: microservice costs with monolith coupling, and a larger blast radius than it looks.
  • Big ball of mud. A monolith without enforced boundaries, where every change touches everything.
  • Chatty services. Fine-grained APIs that need many calls per user request; latency and failure probability multiply.
  • Shared database between services. Schema changes need every team again; isolation exists only on paper.
  • Premature extraction. Boundaries drawn before the domain is understood are expensive to move once they are network calls.

In production

Write the decision down (an ADR) with the forces that drove it and the conditions that would change it. Enforce module boundaries in the build from day one. Before extracting a service, make sure the module already owns its data and talks to others only through its contract; then measure the new hop's latency and set timeouts, retries and circuit breakers on it. Track deployment frequency and lead time per team, P95 per call path and incident blast radius, so the architecture is judged by outcomes rather than diagrams.

Common misconceptions

  • "Microservices are more scalable." Monoliths scale horizontally too; services let you scale parts independently, which matters only when the parts differ.
  • "Microservices are more reliable." They fail more often in total (more parts), but can fail more narrowly if dependencies are designed for it.
  • "A modular monolith is a stepping stone you must leave." Many systems stay modular monoliths for good.
  • "The architecture is a one-time decision." Forces change with team size and load; plan for extraction and consolidation.

Interview angle

Start with a modular monolith unless the requirements name a force for services, and say which force would make you extract which component. Quantify the cost of a split (extra hops × latency, availability of a synchronous chain as the product of its parts), discuss blast radius in terms of the dependency graph, and mention the operational prerequisites: CI/CD per service, tracing, contract versioning, consistency patterns. Interviewers look for trade-offs stated in both directions.

Model assumptions

The simulation is a simplified model, not a benchmark. Requests arrive as a Poisson stream (80/s, 20% checkouts as writes, 80% browsing as reads). The monolith has 32 workers and 15 ms of work per request and a database 2 ms away (16 connections, reads 5 ms, writes 10 ms, lognormal cv 0.3). In the microservices version the gateway (2 ms) routes reads to Catalog (8 ms) and writes to Orders (8 ms), which writes its own database and then calls Payments (6 ms), which writes its own; every internal hop costs 5 ms one way, an illustrative stand-in for network, serialisation, TLS and sidecars. Crashes are modelled as the node refusing requests. The deployment and operational-cost step is a scripted illustration. Numbers show behaviour and orders of magnitude only.

The lesson as textEvery step of the simulation, written out.
  1. 1. The monolith: one process, one database

    Users browse the catalogue and check out, about 80 requests per second, one in five a checkout. One application does everything: catalogue, orders and payments are code in the same process, and calls between them are function calls measured in microseconds.

    Each request crosses the network once on the inside (to the database). Median latency is about 65 ms, most of it the users’ own distance. One build, one deployment, one thing to monitor.

    Scene: Users send 80 requests per second to one monolithic application with one database. Requests take about 65 ms and none fail.

    Key idea: In a monolith, components talk through in-process calls: fast, simple, and they live and die together.

  2. 2. The modular monolith: boundaries in code

    Same deployment, different inside. The code is split into modules along business boundaries (Catalog, Orders, Payments), each with its own schema in the database, a small public interface and no access to the others’ internals. In .NET: one project per module, internal types, one DbContext per module, and architecture tests that fail the build on forbidden references.

    At runtime nothing changes: same process, same calls, same latency, identical numbers on the metrics panel. What changes is how safely teams can work on it, and how cheaply a module could be extracted later.

    Scene: The application is now a modular monolith: Catalog, Orders and Payments modules with their own database schemas, still one process. Latency and throughput are unchanged.

    Key idea: A modular monolith gets most of the design benefit of services (clear boundaries, owned data) without any of the runtime cost.

  3. 3. One bad module takes everything down

    A memory leak in the Payments module grows until, one second in, the process crashes. It restarts two seconds later.

    In between, every request fails: not only checkouts, but browsing too, although the catalogue code was fine. Modules share a process, so they share its memory, its thread pool and its fate. The blast radius of one module’s bug is the whole application. That is true for the modular monolith as well: modules organise code, not failure.

    Scene: The modular monolith crashes after one second because of a bug in the Payments module and restarts two seconds later. In between every request fails, browsing included.

    Key idea: In a single process, the blast radius of any failure is everything.

  4. 4. Microservices: boundaries on the network

    Now each module runs as its own service with its own database, behind an API gateway: browsing goes to Catalog, checkouts go to Orders, which calls Payments.

    Every call between them is a network hop (here 5 ms each way for network, serialisation, TLS and sidecars, illustrative). A checkout used to cross one internal hop; now it crosses four (gateway → Orders → Orders DB → Payments → Payments DB). P95 latency, set by the checkouts, rises by more than half, even though each service does less work than the monolith did.

    Hop counts also multiply failure points: each one can time out, and each needs a timeout, a retry policy and monitoring.

    Scene: The system is split into Catalog, Orders and Payments services with their own databases behind an API gateway. A checkout now crosses four internal network hops instead of one, and P95 latency rises by more than half.

    Key idea: Microservices replace function calls with network calls: every boundary adds latency and a new way to fail.

  5. 5. A smaller blast radius, if the boundaries are right

    The same Payments bug, now in its own service: one second in, Payments crashes.

    Checkouts fail, because Orders calls Payments synchronously. But browsing, four out of five requests, carries on untouched: Catalog runs in a different process and does not depend on Payments. The error rate is about 20% instead of 100%.

    This isolation is not automatic. It holds only because Catalog does not call Payments; a service that depends synchronously on everything (a *distributed monolith*) fails as broadly as a monolith, with more hops. To contain the checkout failure too, Orders would have to accept the order and take payment asynchronously (try the challenge).

    Scene: Payments crashes. Checkouts fail because Orders calls Payments synchronously, but browsing through Catalog keeps working: about 20% of requests fail instead of all of them.

    Key idea: Separate processes shrink the blast radius, but only for paths that do not synchronously depend on the failed service.

  6. 6. Team autonomy, paid for in operations

    Payments is back. The strongest reason for services is organisational: each team builds, deploys and scales its service on its own schedule. The scene shows three independent deployments (gold tokens) rolling out at different times, with no release train and no merge freeze.

    The bill comes with it: three pipelines, three databases with their own backups, versioned APIs between teams, distributed tracing to follow one checkout across four hops, service discovery, more infrastructure and on-call per service. A modular monolith gives teams code ownership, but they still ship together.

    Scripted illustration: deployments and costs are not simulated.

    Scene: A CI/CD system deploys Catalog, Payments and Orders independently, at different times. Annotations list the operational costs: separate pipelines, tracing, service discovery and on-call per service.

    Key idea: Microservices buy independent deployment and scaling per team; the price is operational complexity that grows with the number of services.

  7. 7. Choosing by forces, not fashion

    Put the three side by side:

    - Monolith: lowest latency and ops cost, simplest to debug; boundaries erode without discipline; one blast radius; teams ship together. - Modular monolith: same runtime profile, enforced boundaries, data owned per module; still one deployment and one blast radius. - Microservices: independent deployment, scaling and fault isolation per service; more hops, more failure modes, much more operations.

    A common path: start with a modular monolith, and extract a module into a service when a real force appears: a team that is blocked by shared releases, a component with very different scaling or availability needs, or a technology it must run on. The modules’ clean boundaries are what make extraction cheap.

    Scene: The microservices system with annotations summarising the decision: every network boundary costs latency and operations, so extract services when a concrete force requires it.

    Key idea: Start modular, extract under pressure: let team structure, scaling needs and failure isolation, not fashion, decide where the network boundary goes.

  8. 8. What to remember about architecture trade-offs

    There is no best architecture, only trade-offs you can name. In-process calls are fast and fail together; network calls are slow and fail separately, and only paths that avoid a failed service survive it. Modules give boundaries without runtime cost; services add independent deployment and fault isolation at the price of latency, consistency work and operations.

    Measure the forces (team count and coupling, scaling differences, availability targets, operational maturity) and draw the network boundaries only where they pay.

    Scene: The final microservices system: API gateway, Catalog, Orders and Payments with their own databases, and the CI/CD pipeline deploying them independently.

    Key idea: Choose the architecture whose costs you can afford for the benefits you actually need.