Part 09
Microservices and Architecture Patterns
Decide when to split a system into services, and keep it reliable when you do.
Part context
9.1 The Decision
Chapter outcomes and context
Topics covered: 143 Monolith vs microservices, including when to stay a monolith (Core)
Learning outcomes
- State what microservices buy — independent deployment, independent scaling, team autonomy, fault isolation — and what they cost: distributed-systems problems everywhere (all of Part 8), operational overhead, harder debugging, eventual consistency.
- Apply the honest decision rule: modular monolith first (→ 53); split when team scale or divergent scaling and deployment needs force it. Choosing not to distribute is an architecture decision — Projects 1, 2, 3, 5 and 6 make it deliberately.
9.2 Decomposition and Boundaries
Chapter outcomes and context
Topics covered: 144 Microservices decomposition (Core) · 145 Service boundaries, ownership and Conway's law (Core) · 146 Database per service (Advanced)
Learning outcomes
- Decompose along bounded contexts (→ 56), not technical layers or nouns.
- Recognize a good boundary: high internal cohesion, few cross-boundary calls, one owning team, changes usually land in one service. Conway's law — systems mirror the communication structure of the organizations that build them — makes team design part of architecture.
- (Advanced) Enforce database per service: no shared tables; data crosses boundaries via APIs or events. This is what makes services independent — and what makes cross-service consistency hard (hence outbox → 118 and saga → 139).
- Name the smells: the distributed monolith (services that must deploy together), chatty call chains, entity services owning everyone's data.
9.3 Communication Topologies
Chapter outcomes and context
Topics covered: 147 Inter-service communication (Core) · 148 Backend for frontend (Advanced) · 149 Sidecar and ambassador (Advanced) · 150 Service mesh (Advanced)
Learning outcomes
- Choose per interaction: synchronous (REST/gRPC → 31, 33) for queries; asynchronous events (→ 113) for workflows. Beware call-chain latency addition and failure multiplication.
- (Advanced) Apply Backend for Frontend: a per-client-type aggregation layer (mobile vs. web) keeping client concerns out of domain services. When not to use: one client type — a plain API suffices.
- (Advanced) Apply sidecar (a helper process beside the service handling cross-cutting concerns: proxying, TLS, telemetry) and ambassador (a sidecar specialized as an outbound proxy) — the building blocks of the mesh.
- (Advanced) Adopt a service mesh (sidecar proxies fleet-wide — Istio and Linkerd as examples): mTLS, retries, traffic routing, telemetry moved out of application code. When not to use: a handful of services — libraries and a gateway are simpler.
9.4 Resilience Patterns
Chapter outcomes and context
Topics covered: 151 Circuit breaker (Core) · 152 Retry, timeout and exponential backoff with jitter: retry storms, cascading failure (Core) · 153 Bulkhead (Core) · 154 Graceful degradation (Core)
Learning outcomes
- Set timeouts on every remote call — no unbounded waits — and budget them end to end.
- Retry (primary home of retry policy) only idempotent operations (→ 38, 116), with exponential backoff plus jitter; cap attempts. Understand the failure physics this prevents: retry storms (synchronized retries amplifying load) and cascading failure (one slow dependency exhausting its callers' resources, which exhausts theirs).
- Apply the circuit breaker: closed → open (fail fast) → half-open (probe) — protecting callers and giving the failing dependency room to recover. Simpler alternative for low-traffic paths: timeout plus bounded retries alone.
- Apply the bulkhead: isolated resource pools per dependency so one slow dependency cannot drain every thread and connection.
- Design graceful degradation per feature at design time: stale cache, defaults, disabled features — reduced behavior instead of errors.
9.5 Data Patterns and Evolution
Chapter outcomes and context
Topics covered: 155 CQRS (Advanced) · 156 Strangler fig and anti-corruption layer (Advanced) · 157 Architecture evolution, modernization and technical debt (Advanced)
Learning outcomes (all Advanced)
- Apply CQRS: separate write model from read model(s), synchronized by events; pairs naturally with event sourcing (→ 120). When not to use: one model serves both sides — which is most of the time; the simpler alternative is indexed views or read replicas (→ 72).
- Migrate with the strangler fig — route functionality out of a legacy system behind a facade until it is hollow — and protect the new model with an anti-corruption layer translating between the legacy model and yours.
- Treat architecture as grown, not frozen: expand-and-contract (→ 189), feature flags (→ 188), parallel-run validation. Distinguish deliberate from accidental technical debt; choose among rehost → replatform → refactor → rebuild with risk and measurement, not sentiment.
Done when you can
- Argue both for and against splitting a given monolith, then decide and write the ADR.
- Design service boundaries from bounded contexts and defend the data ownership map.
- Specify the complete resilience envelope for one critical call chain, including how it avoids retry storms and cascading failure.
- Plan a legacy migration that never requires a big-bang cutover.