LESSON 03 · Service boundaries

Monolith or services

Keep one deployable with enforced internal boundaries until you can name the pressure that justifies a split.

SYSTEM VIEW

The decision

Diagram view
Deployables—
Network calls—

Watch one request cross one deployable, then four services, and see which pressure earns a split.

  1. Users send POST /invoices/41/pay to the Monolith. Inside it, the Accounts, Invoices, Payments and PDF modules call each other as functions, and one Database transaction saves the result. There is one deployable to ship.

    Modules
    Accounts, Invoices, Payments, PDF
    Between them
    function calls

    What changed

    • POST /invoices/41/pay
    • 4 modules, 1 deployable
  2. The Monolith becomes four services, each with its own deploys, dashboards and versioned contract. The request needs all four, over 3 network calls. Each is 99.9% available, so with independent failures it succeeds about 99.6% of the time (0.999 to the 4th power).

    Each service
    99.9%
    All four
    ≈ 99.6%
    Math
    0.999⁴

    What changed

    • Monolith
    • 4 services, each 99.9%
    • 3 network calls
  3. Invoices service saves invoice 41, then its charge call to Payments service times out, and nobody knows whether the charge went through. One transaction has become steps that can half-finish.

    Was
    one transaction
    Now
    steps that half-finish

    What changed

    • Charge call timeout
    • Invoice 41 saved, charge unknown
  4. The four services fold back into one Monolith, boundaries kept inside: each module has a small interface and owns its tables, and a check in the build stops other modules querying them. It keeps one deploy and can still use a database transaction.

    Interface
    small
    Tables
    one owner each
    Enforced
    in the build

    What changed

    • 4 services
    • Module boundaries
    • Build check
  5. At month end, PDF generation uses so much memory that the Monolith goes down and takes every feature with it. That is a named pressure, failure isolation; the other three are team coordination, deploy conflicts and independent scaling.

    Pressure
    failure isolation
    The others
    coordination, deploys, scaling

    What changed

    • Month-end PDFs
    • Monolith out of memory
    • Every feature down
  6. PDF generation moves to PDF workers, a separate pool of processes built from the same codebase. Their memory use can’t kill the Monolith, which serves pages again. It is still one deployable, with no new network contract or database.

    Code
    same codebase
    New contract
    none

    What changed

    • PDF workers
    • Monolith back up
  7. If PDFs still need their own runtime, or a team comes to own them, extract that one module: PDF workers become a PDF service. It adds a network call, retries, versioning and a second deploy, so check that the pressure actually fell.

    Extract
    one module at a time
    Start with
    clearest owner, fewest shared tables
    Head count
    settles nothing

    What changed

    • PDF workers
    • PDF service, own deploy
    • 1 network call

Space plays · ← → step · Home resets

THE IDEA

How it works

A service boundary is expensive. Calls that were function calls can now time out, one database transaction becomes several steps that can half-finish, and each service needs its own deploys, dashboards, and versioned contract. Failures multiply too: if a request needs 4 services that are each 99.9% available, and failures are independent, it succeeds about 99.6% of the time (0.999 to the 4th power).

A modular monolith keeps one deployable but enforces internal boundaries. Each module exposes a small interface and owns its tables, and other modules do not query those tables directly. An automated check in the build should enforce this, because good intentions erode. You keep one deploy and can still use a database transaction when you need one, and a clean module is cheaper to extract later.

Extract a service when you can name the pressure. Team coordination: for example, three teams must agree before any of them can ship. Deploy conflicts: one team’s failing tests or risky release regularly blocks the others. Independent scaling: one part needs very different resources, and running it as a separate worker pool from the same codebase was not enough. Failure isolation: a crash-prone component keeps taking down unrelated features.

No head count settles this. A five-person team may rightly isolate a PDF renderer that keeps crashing web servers, and a large team may do well in one codebase with a fast test suite. Extract one module at a time, starting with the clearest owner and the fewest shared tables, then check whether the pressure actually fell.

DECISION POINT

A seven-person team runs one codebase. Month-end PDF generation uses so much memory that web servers are killed, and a teammate proposes a separate PDF microservice with its own repository, database, and API. What do you do?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • A modular monolith gives you boundaries without network failures.
  • Extract a service for a named pressure: coordination, deploys, scaling, or failure isolation.
  • Try a separate worker pool from the same codebase before a new service.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

What makes a monolith modular rather than merely one large codebase?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.