13.1 · Five shapes
| Shape | When |
|---|---|
| Monolith | Small team; one domain; speed beats scale. |
| Modular monolith | Same deployable; strict internal boundaries. Modern default for most products. |
| Microservices | Multiple teams owning distinct domains; independent deploy cadence required. |
| Service mesh | Many services; uniform retries, mTLS, traffic shaping. |
| Cells / micro-frontends | Split user populations into isolated stacks for blast-radius control. |
13.2 · Monolith done right
- One deployable, one DB, one repo.
- Mature framework (Rails, Django, Spring, Phoenix, Laravel, .NET).
- Boundaries via packages, not network hops.
- Background jobs in-process with a queue worker.
- Highest speed-to-revenue for < 10 engineers.
13.3 · Modular monolith — the underrated middle
- One deployable; strict internal modules with explicit APIs between them.
- Extract a service later, cheaply, because boundaries were clean.
- Tools: Java modules / Kotlin Gradle subprojects / Rust workspaces / TS workspaces + Nx tags.
13.4 · Microservices — only when you need them
| Pro | Con |
|---|---|
| Independent deploys | Network + serialisation tax on every call |
| Tech polyglot | Operational footprint multiplies |
| Per-service scaling | Distributed debugging is 10× harder |
| Smaller blast radius | Need mesh, OTel, contracts to stay sane |
13.5 · BFF — Backend For Frontend
One backend tailored per client surface (web, iOS, Android, partner). Composes downstream services; pairs with GraphQL or tRPC.
13.6 · Service mesh — Istio, Linkerd, Consul, Cilium
- Sidecar proxy (Envoy) per pod — or sidecar-less (Cilium eBPF, Istio Ambient).
- Uniformly: mTLS, retries, timeouts, circuit breaking, traffic shifting, telemetry.
- Cost: ops complexity. Add when service count > ~10.
13.7 · Hexagonal / Clean / Onion
Same idea, three names: domain at the centre, ports (interfaces) around it, adapters (DB, HTTP, queue) on the outside. Lets you swap infrastructure without touching domain logic.
13.8 · DDD — Domain-Driven Design
- Strategic: bounded contexts, context maps, ubiquitous language. "Order" in shipping ≠ "Order" in billing.
- Tactical: entity, value object, aggregate, repository, domain event, factory.
- Pattern relationships: partnership, customer–supplier, conformist, anti-corruption layer.
- Use heavily when the domain is the hard part (insurance, lending, healthcare).
13.9 · CQRS & Event Sourcing
- CQRS: separate models (and possibly stores) for commands vs queries.
- Event sourcing: store events, derive state. Full audit history; rebuild any read model.
- Pairs with: Kafka, EventStoreDB, Marten, Axon.
- Cost: complexity. Use only when audit + temporal queries justify it.
13.10 · Strangler fig — the migration pattern
- Route new traffic through a façade / proxy.
- Move features one at a time; old and new run in parallel.
- When the legacy has no traffic left, retire it.
13.11 · Integration patterns (EIP — Hohpe / Woolf)
| Pattern | Idea |
|---|---|
| Message channel | Producers / consumers connected by typed channels. |
| Content-based router | Inspect message → route to handler. |
| Aggregator | Collect related messages; emit one. |
| Scatter-gather | Fan out, collect all, fan in. |
| Process manager | Stateful coordinator across messages. |
| Message translator | Adapter between schemas. |
| Anti-corruption layer | Wrap a legacy system so its model can't leak. |
13.12 · Self-check
Q1 · A 6-engineer team starting a new SaaS picks…
15 microservices
A modular monolith
A service mesh from day 1
CQRS + event sourcing