Skip to main content

Module 2: Microservices & Service Decomposition

Primary texts: Building Microservices (Sam Newman, 2nd ed.) and Microservices Patterns (Chris Richardson) Selective support: Fundamentals of Software Architecture (Richards & Ford) microservices chapter, System Design Primer application-layer and communication chunks, Team Topologies (Skelton & Pais) for organization alignment

This guide is the primary teacher. You do not need to read the source books front-to-back. You do need to leave this module able to (a) decide when microservices are the right tool, (b) draw defensible service boundaries on a real system, (c) own data per service without a shared database, and (d) operate the resulting distributed system with contracts, resilience patterns, and tracing.


Scope of This Module

Microservices is not "many small services" and it is not "containerize the monolith." It is a specific architectural style whose value depends entirely on organizational and operational maturity. This module is about learning when to pay that cost and how to decompose a system without creating a distributed monolith.

What it covers in depth:

  • the microservices distillation: independent deployability, team ownership, and bounded business scope
  • the cost model: what you must have before the style pays back
  • monolith-first defaults and the strangler-fig migration pattern
  • bounded contexts as service boundaries and decomposition heuristics by business capability, subdomain, and noun/verb
  • anti-patterns: distributed monolith, entity services, shared database, "CRUD-a-service"
  • database-per-service and the data-ownership discipline
  • service contracts (sync APIs, async events, tolerant readers) and consumer-driven contract testing
  • synchronous vs asynchronous communication and when each is right
  • service discovery, API gateways, and the BFF (Backend-for-Frontend) pattern
  • resilience primitives: timeouts, retries, circuit breakers, and bulkheads
  • distributed tracing, correlation IDs, and observability for request flow
  • deployment independence: versioning, backward compatibility, zero-downtime
  • Conway's Law and stream-aligned teams

What it deliberately does not cover here:

  • saga orchestration and distributed transaction mechanics (S8 M3 event-driven architecture)
  • service mesh, Kubernetes operators, and runtime platform details (production path, later)
  • DDD strategic and tactical mechanics as a separate course (already built in S7 M3)
  • full SRE/SLO math (S8 M4 scale, reliability, performance)

Before You Start

Answer closed-book:

  1. In one sentence, what makes a service a "microservice" rather than just a service?
  2. Give one concrete reason a three-engineer team should not build microservices yet.
  3. What is the difference between a bounded context and a service?
  4. Why is "two services sharing the same database" often a warning sign?
  5. If service A calls service B synchronously and B is slow, what happens to A without a timeout?

Diagnostic Interpretation

4-5 solid answers -- Ready for the full path. 2-3 solid answers -- Continue, but expect extra time in Clusters 2 and 3. 0-1 solid answers -- Revisit S7 M2 (architecture patterns) and S7 M3 (bounded contexts) briefly. Microservices is a deployment style of ideas that live there first.


What This Module Is For

You have probably seen one of two failure patterns already:

  • a monolith that has become a "big ball of mud" and cannot be safely changed
  • a set of "microservices" that must all be deployed together and share one database

This module teaches you to avoid both. After it, you should be able to answer:

  • should this system be microservices at all, or a modular monolith?
  • where should the service seams go, and what data does each side own?
  • what contract do the services expose, and how do we change it without breaking consumers?
  • how do we communicate between services without turning a slow dependency into a cascading outage?
  • how do we tell, in production, which service is responsible for a slow or failing request?

This module feeds directly into:

  • S8 M3 Event-Driven Architecture -- the async side of service contracts
  • S8 M4 Scale, Reliability & Performance -- the SLO/SLI view of the resilience primitives
  • S8 M5 Technical Leadership & Strategy -- the ADR for "monolith vs microservices" is one of the most common architecture decisions you will write

Concept Map


How To Use This Module

Work in order. The later clusters only make sense once the decomposition and data-ownership reflexes are stable.

Cluster 1: When and Why Microservices

OrderConceptTypeFocus
1The Microservices Distillation: Independent Deploy, Team-Owned, BoundedPRIMARYWhat actually defines the style vs what is just "services"
2Why Not Microservices: The Cost ModelPRIMARYThe capabilities you must already have before it pays back
3Monolith-First and Strangler-Fig MigrationPRIMARYDefault posture and the single migration pattern worth memorizing

Cluster mastery check: Can you say, for a specific team and product, whether microservices is the right style and why?

Cluster 2: Finding Service Boundaries

OrderConceptTypeFocus
4Bounded Contexts as Service BoundariesPRIMARYThe DDD concept that actually carries across to deployment units
5Decomposition Heuristics: Capability, Subdomain, Noun/VerbPRIMARYThree lenses, one answer -- and what to do when they disagree
6Avoiding Distributed-Monolith and Entity-Service Anti-PatternsPRIMARYHow otherwise-reasonable decompositions fail

Cluster mastery check: Can you split a given monolith into three named services and justify the data each one owns?

Cluster 3: Data Ownership and Contracts

OrderConceptTypeFocus
7Database-Per-Service and the Shared-DB TemptationPRIMARYWhy shared databases silently re-couple services
8Service Contracts: Sync APIs, Async Events, Tolerant ReadersPRIMARYThe three contract shapes and the tolerance discipline
9Consumer-Driven Contract TestingPRIMARYCatching breaking changes before the deploy

Cluster mastery check: Can you write both an OpenAPI fragment and an event schema for the same cross-service interaction?

Cluster 4: Service Communication

OrderConceptTypeFocus
10Synchronous REST/gRPC vs Asynchronous EventsPRIMARYPicking the right style per interaction, not per system
11Service Discovery, API Gateways, BFF PatternPRIMARYEdge vs internal routing and client-shaped aggregations
12Resilience: Timeouts, Retries, Circuit Breakers, BulkheadsPRIMARYStopping one slow dependency from taking down the cluster

Cluster mastery check: Can you draw the timeline of a call from frontend to a failing downstream service with every resilience primitive in place?

Cluster 5: Operating Microservices

OrderConceptTypeFocus
13Distributed Tracing and Correlation IDsPRIMARYReconstructing one request across many services
14Deployment Independence: Versioning and Backward CompatibilityPRIMARYWhy independent deploy is a property of contracts, not of pipelines
15Team Topology: Conway's Law and Stream-Aligned TeamsSUPPORTINGThe organizational shape that makes all of the above actually work

Cluster mastery check: Can you point at a trace from production and explain which service owns the p99 latency and which team would be paged?

Then work these practice pages:

OrderPractice pathFocus
1Decomposition LabTurning a monolith into named services with explicit owned data
2Contracts and Data WorkshopWriting an OpenAPI fragment and an event schema for the same flow
3Resilience ClinicTimeouts, retries, circuit breakers, and bulkheads on one call path
4Microservices KatasDecompose e-commerce, write a contract test, wire a circuit breaker, model a distributed trace

Use Module Quiz after the concept and practice path. Use Reference and Selective Reading and Learning Resources only for targeted reinforcement.


Learning Objectives

By the end of this module you should be able to:

  1. Propose and defend whether a given product should use microservices, a modular monolith, or a hybrid.
  2. Decompose a monolith into 3-6 named services with explicit owned data and a migration sequence.
  3. Identify and remove distributed-monolith and entity-service anti-patterns in a proposed design.
  4. Design database-per-service ownership and explain how cross-service data is obtained (composition vs replication vs events).
  5. Write a service contract as an OpenAPI fragment and an equivalent event schema, including compatibility rules.
  6. Explain consumer-driven contract testing and run a thought-experiment contract test for a named interaction.
  7. Choose synchronous vs asynchronous per interaction and justify the choice.
  8. Apply timeouts, retries (with backoff + jitter), circuit breakers, and bulkheads to a specific call path and trace what happens under a downstream outage.
  9. Read and interpret a distributed trace, including correlation IDs, span hierarchy, and where latency is concentrated.
  10. Describe a team topology that preserves deployment independence and explain Conway's Law in one paragraph.

Outputs

  • one decomposition memo for a named monolith (3-6 services, owned data table, first strangler cut)
  • one OpenAPI fragment and one matching event schema for a single interaction
  • one consumer-driven contract test specification (provider, consumer, and one example)
  • one resilience sequence diagram (mermaid) for a specific call path
  • one mock distributed-trace waterfall with correlation IDs and p99 narration
  • one ADR-style 1-page memo arguing "microservices" or "modular monolith" for a real or chosen system
  • one mistake log with at least 12 tagged anti-patterns (shared db, entity service, synchronous fan-out, retry without backoff, timeouts absent, contract break, lockstep deploy, etc.)
  • a set of flashcards covering the 15 concepts

Completion Standard

You have completed this module when all of these are true:

  • you can decide when not to use microservices with concrete evidence, not aesthetics
  • you can draw service seams from bounded contexts and business capability, and explain where they disagree
  • you can refuse a shared database and explain the alternatives in sentences, not buzzwords
  • you can write a contract and a compatibility rule without looking it up
  • you can describe the full path of a request from edge to downstream failure with every resilience primitive in place
  • you can read a trace and say what the owning team should change

If the answer sounds familiar but you cannot name the owned data and the failure mode, the module is not complete.


Reading Policy

  • Concept pages are the main path.
  • Local book chunks are selective reinforcement, not a second syllabus.
  • Read this only if stuck means try the concept page, self-check, and drill first.
  • Optional deep dive means nuance, not required progression.
  • For DDD framing (subdomain, ubiquitous language, aggregates), lean on Semester 7, Module 3 -- this module only restates what it needs and adds the deployment side.

Suggested Weekly Flow

DayWork
1Concepts 1-3, write the cost-model memo for a chosen product
2Concepts 4-6, draft a decomposition of an e-commerce monolith
3Concepts 7-9, write an OpenAPI fragment and matching event schema
4Concepts 10-12, draw the resilience sequence diagram
5Concepts 13-15, sketch a distributed trace and a team topology
6Practice pages 1-2 and targeted book chunk reinforcement
7Practice pages 3-4, quiz, and mistake-log cleanup

Reference

If you need exact links into the local chunked books, use Reference and Selective Reading.


Rich Learning Pages

Worked Examples | Guided Labs | Case Studies | Mistake Clinic | Reading Guide | Capstone Thread