Skip to content
Ylabator
Decision guideIntermediate

Single Service vs. Microservices

Start as one deployable service with enforced module boundaries, and split out a service only when a measured need pays for the network, versioning and operations cost.

5 min read / Updated / Last checked

Format
Decision guide · Intermediate
Who it is for
Founders and the builders they hire
You leave with
Choose between one service and several, and enforce module boundaries so a later split stays cheap.

The problem

On July 10, 2018, Segment's engineering team explained why it had folded more than 140 microservices back into one service. Each data destination had its own service, its own repository and its own queue. Shared libraries drifted across versions, every change to them meant redeploying 140+ services, and at the low point three full-time engineers spent most of their time keeping the system alive. After the merge, one engineer could deploy the service in minutes [1].

The cost was structural. Every boundary between services was a network call, a deployment pipeline and a version to keep compatible, multiplied by the number of services.

Founders meet the same choice early, often in an agency proposal or a diagram an AI tool produced. A drawing with eight boxes looks more serious than one with a single box. For a team of five shipping its first product, the eight boxes usually mean eight deploys to coordinate, eight sets of logs to search and data split across stores that can no longer be updated in one transaction. The question is not which style is modern. It is which costs the product can afford this year, and how to keep the option to split later.

How it works

A single service (often called a monolith) is one deployable unit: one build, one release, usually one database. Microservices are separately deployed services that talk over the network, each owning its own data. A modular monolith sits between them: one deployable unit whose code is divided into modules with enforced boundaries, so each module only uses another through its public interface.

Shopify runs the modular model at scale. Its core Rails monolith held 2.8 million lines of Ruby and 500,000 commits in 2020, split into 37 components. A tool called Packwerk, used on about a third of those components, flags changes that break the agreed dependencies before they merge [2].

A 2023 paper by Google engineers lists what splitting into microservices costs [3]:

  • Performance. Serializing data and sending it across the network adds latency to calls that used to be function calls.
  • Correctness. Different versions of services run side by side and interact in ways nobody tested.
  • Management. There are n binaries to build, test and deploy, each on its own schedule.
  • Frozen APIs. Once another service depends on an API, changing it means coordinating releases.
  • Slower development. A change that spans services cannot be deployed atomically.

The authors' proposal is to write the application as a logical monolith of modules and decide physical placement separately [3]. Martin Fowler reached a similar rule from practice in 2015: almost every successful microservice story he knew started with a monolith that grew too big, while almost all systems built as microservices from scratch ended up in serious trouble [4]. He also names prerequisites before running microservices at all: provisioning a server in hours, monitoring that catches serious problems quickly, and a deployment pipeline measured in hours, not days [5].

Splitting pays when one part of the system differs sharply from the rest: it needs to scale on its own, it must fail without taking the rest down, it holds data that needs separate isolation, or a separate team ships it on its own schedule.

What each architecture costs a small team

Fig. 01
What each architecture costs a small team
DimensionModular monolithMicroservices
Deployone artifact, atomicone pipeline per service
Internal callfunction callnetwork and serialization
Data changeone transactioncoordination across stores
Debuggingone log, one tracedistributed tracing
Scalingwhole app scaleseach service scales
Team fitfew teams, one cadencemany teams, own cadences
A modular monolith keeps calls, deploys and transactions local; microservices trade that for independent scaling and release.

By the numbers

microservices Segment consolidated into a single service [1]
140+
full-time engineers spent mostly on keeping Segment's services alive [1]
3
lines of Ruby in Shopify's modular monolith, split into 37 components [2]
2.8M
lower latency in Google's logical-monolith prototype versus the status quo [3]
up to 15x
of catastrophic failures in a study cited by the Google paper came from interactions between versions [3]
two-thirds
TeamBeforeAfterReported result
Segment, 2018140+ services, a queue and repo per destinationOne service, one repo, shared worker poolShared library improvements rose from 32 to 46 in a year, one engineer deploys in minutes [1]
Shopify, 2020One large Rails codebaseSame deployable, 37 components with checked boundariesPackwerk on about a third of components, violations caught before merge [2]
Google prototype, 2023Hand-split microservicesLogical monolith, runtime decides placementUp to 15x lower latency and up to 9x lower cost [3]
Three teams that changed their service boundaries, as each reported it [1][2][3]

Read the Google figures as a ceiling from a research prototype, not a forecast for any one product [3]. The Segment numbers matter more for a startup, because they describe staff time. When most of three engineers' weeks go to keeping services alive, that time is not going to features.

None of these teams went back to an unstructured codebase. Shopify kept one deployable unit but enforced boundaries inside it [2]. That is the part to copy: the boundaries make a later split a refactor instead of a rewrite.

Implementation

Lay the code out as modules with one public entry point each, for example src/modules/bookings/index.ts, src/modules/billing/index.ts, src/modules/notifications/index.ts. Everything else inside a module folder is private. Each module owns its tables, and other modules read that data through the owning module's functions, not with their own SQL.

AI coding tools will happily import a helper from deep inside another module, because it compiles. Shopify uses Packwerk for this in Ruby [2]. For a TypeScript codebase, the short script below does the same job in CI without extra dependencies.

check_boundaries.pypython
"""Fail CI when one module imports another module's internals.
Layout: src/modules/<name>/index.ts is the public API, everything else is private.
Usage: python check_boundaries.py src/modules"""
import re
import sys
from pathlib import Path

IMPORT = re.compile(r"""from\s+['"]([^'"]+)['"]""")


def target_module(spec: str, source: Path, root: Path) -> tuple[str, str] | None:
    """Return (module, path inside module) for an import, or None if external."""
    if spec.startswith("@/modules/"):
        parts = spec.removeprefix("@/modules/").split("/")
    elif spec.startswith("."):
        resolved = (source.parent / spec).resolve()
        try:
            parts = list(resolved.relative_to(root.resolve()).parts)
        except ValueError:
            return None  # import points outside src/modules
    else:
        return None  # npm package
    return parts[0], "/".join(parts[1:])


def check(root: Path) -> list[str]:
    errors = []
    for source in root.rglob("*.ts"):
        own = source.relative_to(root).parts[0]
        for spec in IMPORT.findall(source.read_text(encoding="utf-8")):
            hit = target_module(spec, source, root)
            if hit is None or hit[0] == own:
                continue
            module, inner = hit
            if inner not in ("", "index"):
                errors.append(f"{source}: imports {module} internals via '{spec}'")
    return errors


if __name__ == "__main__":
    problems = check(Path(sys.argv[1]))
    print("\n".join(problems) or "OK: modules talk only through index.ts")
    sys.exit(1 if problems else 0)

It reads import ... from statements, resolves relative paths and the @/modules/ alias, and flags any import that reaches past another module's index.ts. It needs Python 3.10 or later. Add it to the CI job next to the type check and to the AI tool's project instructions: "Modules talk only through index.ts. Run check_boundaries.py before proposing a change."

When a split is proposed, ask for a one-page case that answers four questions in numbers:

  1. What load, failure or isolation need does this module have that the rest does not?
  2. What does it cost to run, deploy and monitor separately?
  3. How does data stay consistent across the new boundary?
  4. Are Fowler's prerequisites (fast provisioning, monitoring, a deployment pipeline) already in place [5]?

Record the answer as an architecture decision record (see Architecture Decision Records (ADRs)).

Test it

The first check runs on every pull request. The other three run before any split.

  • Add a deliberate violation on a branch: import { repo } from "@/modules/bookings/internal/repo" inside billing. Expected: the script prints the file and the offending import and exits with status 1. Remove the line and it prints OK and exits 0.
  • Before any extraction, run a load test on the module in place. If the monolith handles the projected peak with the module inside it, the scaling argument for a split is gone.
  • Check that the module's tables are touched only by its own code: search the repository for its table names outside the module folder. Expected: no hits. A module that shares tables cannot be split without a data migration first.
  • Confirm every cross-module call goes through index.ts. That list of functions is the future API of the service, so review it the way an API would be reviewed.

Decision

Ship the first product as one deployable service with enforced module boundaries and one database. It is the cheapest thing to deploy, debug and change, and the boundaries keep the option to split open.

  • Default: modular monolith, one database, boundary check in CI from the first week.
  • Split one module only when there is a measured scaling, failure or isolation need, or a separate team with its own release schedule.
  • Before the first split, have monitoring, fast provisioning and a deployment pipeline in place [5].
  • Treat a proposal with many services for a pre-revenue product as a cost question. Ask what each box costs to run each month and who is on call for it.

Sources

  1. [1]Goodbye Microservices (opens in a new tab)Alexandra Noonan, Twilio Segment, July 2018
  2. [2]Under Deconstruction: The State of Shopify's Monolith (opens in a new tab)Philip Müller, Shopify Engineering, September 2020
  3. [3]Towards Modern Development of Cloud Applications (opens in a new tab)Ghemawat et al., HotOS '23, June 2023
  4. [4]MonolithFirst (opens in a new tab)Martin Fowler, June 2015
  5. [5]MicroservicePrerequisites (opens in a new tab)Martin Fowler, August 2014

Technical guidance, not legal or security certification.

Need a technical review of an AI-built MVP?

Discuss your build