Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 20 min · revision 1

What microservices buy and what they cost

Trace each benefit of microservices to its mechanism and the condition it needs, test the main one against your own change history, recognise a distributed monolith, state Conway's law accurately, and name the contexts where microservices do not fit.

Contentsand lesson path

What you will learn

  • Decide whether microservices are justified for a context, using team structure, deployment-independence needs and operational prerequisites.

Prerequisites: Strategic Domain-Driven Design

01. Why it matters

Imagine an online shop where nine teams work in one codebase that ships as one unit every second Tuesday. A one-line fix waits for the release train, and when one team's change breaks a test, everyone waits. Someone proposes microservices, so that each team can release on its own.

Before you agree, ask what the split would buy this organisation and what it would cost every day afterwards. Distributed styles introduced microservices and the price of distribution priced each network boundary. This lesson goes deeper: the mechanism behind each benefit, the condition it needs, a check of that condition against your change history, and the failure mode that pays every cost for almost no benefit.

02. What a split buys and costs: three conditions to check

In this skill a microservice is owned by one team, deployed on its own, owns its data and is built around one business capability, the shape James Lewis and Martin Fowler described in 2014. The price of distribution already rated the benefits as conditional claims and priced the costs. In short: separate units release, scale and fail separately only when changes stay inside one unit, when parts have different load profiles (a monolith also scales out by running more copies) and when callers can carry on without the callee; every unit adds a pipeline, dashboards, an owner on call and the microservice premium. This lesson goes further on three of those conditions.

  • Independent deployment is the main purchase, and its condition can be measured before you split: the next section counts how many past changes would cross a proposed boundary. When the gain is limited to one part, such as one module with a very different load, extract that part first and leave the rest (legacy modernisation).
  • Fault isolation needs design, not only a new process. A crash in one process cannot corrupt another process's memory, but a hang travels along synchronous calls: a page that waits ten seconds for a reviews service with no fallback is stuck whenever reviews are stuck (how cascading failures happen).
  • Consistency is the cost that surprises teams most. In one database, saving an order and reducing stock can be one transaction. With two services and two databases, one transaction across both would need a distributed-transaction protocol such as two-phase commit, which microservices usually avoid because it ties the participants' availability and locks together. So the design must handle an order saved while the stock change failed, usually with local steps and compensating actions (distributed data patterns).

Who can release alone depends on team boundaries, which brings in Conway's law. Melvin Conway's paper How Do Committees Invent? was rejected by the Harvard Business Review and published by Datamation in April 1968. In Conway's own short form, any organisation that designs a system will produce a design whose structure copies the organisation's communication structure; Fred Brooks later named it Conway's law. The mechanism is practical: two modules fit together only if their builders talk, so interfaces form where conversation is easy. Conway calls it a valid sociological observation, not a joke; like the price-of-distribution lesson, read it as a strong tendency rather than a law of nature.

It is about communication, not the organisation chart: two teams that plan together daily behave like one. A service boundary that cuts through one team's daily work will be crossed constantly, while a boundary between teams that rarely talk hardens into a contract. Some organisations reshape teams first so that the architecture they want becomes the easy one, often called the inverse Conway manoeuvre. Conway's corollary: the first design is rarely the best, so stay flexible enough to change it.

03. Check the main benefit against your history

Independent deployment has a condition you can check before splitting: do your changes stay inside the proposed services? Version control records which files each change touched, so map files to services and count.

The first script writes a made-up shop history in the format git log prints; the second reads any such log. Both need Python 3.12 or newer, standard library only. Put them in an empty folder.

Python · make_history.py
"""make_history.py: write a made-up change history in the format `git log` prints."""
import random

rng = random.Random(42)
# What one change usually touches in this imaginary shop, and how often it happens.
KINDS = [
    (["catalog"], 22), (["payments"], 14), (["shipping"], 14), (["orders"], 10),
    (["cart", "pricing"], 24), (["pricing"], 6), (["cart"], 4),
    (["orders", "payments"], 4), (["orders", "payments", "shipping"], 2),
]
FILES = ["models.py", "rules.py", "views.py", "tests/test_main.py"]

with open("changes.log", "w") as out:
    for _ in range(120):
        areas = rng.choices([k for k, _ in KINDS], weights=[w for _, w in KINDS])[0]
        out.write(f"commit {rng.getrandbits(28):07x}\n\n")
        for area in areas:
            for name in rng.sample(FILES, rng.randint(1, 2)):
                out.write(f"src/{area}/{name}\n")
        if rng.random() < 0.2:  # some changes also touch shared build files
            out.write("pyproject.toml\n")
        out.write("\n")
print("wrote 120 changes to changes.log")
Python · co_change.py
"""co_change.py: how many past changes would cross a proposed service boundary?

Usage: python3 co_change.py changes.log
Make the log from a real repository with:
    git log --name-only --format='commit %h' --since='12 months ago' > changes.log
"""
import re
import sys
from collections import Counter
from itertools import combinations

# The proposed split: path prefix -> service. Edit it to match your repository.
SERVICES = {
    "src/catalog/": "catalog", "src/pricing/": "pricing", "src/cart/": "cart",
    "src/orders/": "orders", "src/payments/": "payments", "src/shipping/": "shipping",
}
HEADER = re.compile(r"commit [0-9a-f]{4,40}")  # one line per commit, from --format


def read_changes(lines):
    """Yield the set of file paths of each commit in `git log --name-only` output."""
    paths = None
    for raw in lines:
        line = raw.strip()
        if HEADER.fullmatch(line):
            if paths:
                yield paths
            paths = set()
        elif line and paths is not None:
            paths.add(line)
    if paths:
        yield paths


def services_touched(paths):
    return {svc for path in paths
            for prefix, svc in SERVICES.items() if path.startswith(prefix)}


def main(log_path):
    spread, pairs, total = Counter(), Counter(), 0
    with open(log_path, encoding="utf-8") as log:
        for paths in read_changes(log):
            touched = services_touched(paths)
            if not touched:  # docs or build files only: outside the split
                continue
            total += 1
            spread[min(len(touched), 3)] += 1
            pairs.update(combinations(sorted(touched), 2))
    print(f"changes that touch a proposed service: {total}")
    if not total:
        print("no change touched a proposed service: edit SERVICES to match the paths")
        return
    for n, label in [(1, "1 service"), (2, "2 services"), (3, "3 or more")]:
        print(f"  touch {label:<11}{spread[n]:4}  ({spread[n] / total:.0%})")
    print("pairs that change together most often:")
    for (a, b), count in pairs.most_common(4):
        print(f"  {a + ' + ' + b:<22}{count:3}")


if __name__ == "__main__":
    main(sys.argv[1])

Before you run them, predict: which pair of services will change together most, and what share of changes will cross a boundary?

Terminal
python3 make_history.py
python3 co_change.py changes.log
Expected output (make_history.py; seeded, so it matches exactly)
wrote 120 changes to changes.log
Expected output (co_change.py)
changes that touch a proposed service: 120
  touch 1 service    85  (71%)
  touch 2 services   32  (27%)
  touch 3 or more     3  (2%)
pairs that change together most often:
  cart + pricing         25
  orders + payments      10
  orders + shipping       3
  payments + shipping     3

About 71% of changes stay inside one service and would ship independently. Of the 35 that cross a boundary, 25 touch Cart and Pricing: with different owners, about one release in five (25 of 120) would need both teams. You could keep Cart and Pricing together, move the boundary (put the basket discount rules on the cart side), or invest in a stable contract between them. Orders with Payments, at 10, is worth watching.

The model is simplified. A commit is only a proxy for a change: a feature can span several commits and a commit can bundle unrelated edits, so pull requests or tickets are better units if you have them, over a long window. It also ignores runtime calls, which lesson 3 checks. For your own code, run git log --name-only --format='commit %h' --since='12 months ago' > changes.log and edit SERVICES.

Terminal · a log in which no path matches SERVICES
printf 'commit 1a2b3c4\n\ndocs/readme.md\n' > docs-only.log
python3 co_change.py docs-only.log
Expected output
changes that touch a proposed service: 0
no change touched a proposed service: edit SERVICES to match the paths

04. The distributed monolith

A distributed monolith is deployed as many services but still has to change, deploy or fail together, paying every cost above for almost no benefit. Typical symptoms:

  • features routinely need coordinated releases of several services, often in a fixed order;
  • services read or write each other's tables;
  • a shared library of domain classes forces every service to rebuild when it changes;
  • long chains of synchronous calls, so one slow service stalls the rest;
  • testing needs every service running at matching versions.

Each symptom is coupling that survived the split, usually because boundaries followed layers or tables instead of business capabilities, or came before the team understood the domain. A release calendar makes the coupling easier to live with but leaves it in place. The fix is to move the boundary: merge services that nearly always change together, or re-cut them along what changes together, as lesson 3 does.

05. When not to use microservices

Microservices are usually a poor fit when:

  • one or two teams own the whole system, so there is little release contention to remove;
  • the domain is new or changing fast, so today's boundaries will move, and moving code between services is far harder than between modules;
  • the prerequisites of lesson 2 are missing: automated deployment, monitoring and tracing, and an owner on call per service;
  • most operations must change data that would land in several services at once, such as a ledger and its balances;
  • a request must pass many small steps inside a tight latency budget.

There, a modular monolith gives clear modules and owned data inside one deployable unit, and keeps the option to extract a module once evidence appears, which is the reasoning behind Fowler's monolith first advice.

What if the shop grows from two teams to eight, and the co-change report shows most changes staying inside modules? Release contention is now real and the boundaries have survived a year of change, so the analysis that said not yet can say yes for the modules with the most contention.

06. Check your understanding

Practice check · 3 questions

Benefits, costs and conditions

Predict what each split really changes.

Q1. A shop moved its delivery-estimate widget into its own service so that bugs there could no longer break the basket page. The basket page still calls it synchronously, waits up to 8 seconds and has no fallback. The delivery-estimate service starts to hang. What happens to the basket page?
Q2. In the monolith, placing an order inserted the order and reduced stock in one database transaction. Orders and Inventory are now separate services with separate databases. Which new situation must the design handle?
Q3. Before a split, a team runs co_change.py on a year of history. 41% of changes touch both the proposed Accounts and Billing services, which would belong to different teams. What does this predict for the split as drawn?
Practice only: not graded, not saved, not evidence.

07. Apply it

Choose the context for this skill's practice deliverable: an online grocery that sells same-day delivery slots, or an e-commerce system you know. Write a half-page go/no-go note.

  1. Describe the teams and how they communicate. Mark any boundary that would cut through one team's daily work.
  2. For each benefit you expect, write its condition and whether it holds now.
  3. Run co_change.py on a real repository with your own SERVICES, or list the capabilities you expect to change together and why.
  4. Decide: split now, extract one part, or stay a modular monolith, and name the evidence that would change your mind.

08. Review prompt

Without looking back: explain the mechanism and the condition behind independent deployment, independent scaling and fault isolation. State Conway's law as Conway wrote it, and give one way it shapes where service boundaries end up. List four symptoms of a distributed monolith, and explain why moving a boundary fixes them when a release calendar does not.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check