11.1 · The five shapes
| Shape | When |
|---|---|
| Monolith | 0–20 engineers; one domain; speed matters more than scale. |
| Modular monolith | Same deployable, strong internal boundaries; the modern default for most products. |
| Microservices | Multiple teams owning distinct domains; independent deploy cadence. |
| Service mesh | You have many services and need uniform retries, mTLS, traffic shaping. |
| Cells / micro-frontends | You can split user populations into isolated stacks for blast-radius control. |
11.2 · Monolith done right
- Single deployable; one DB; one repo.
- Boring tech; mature framework (Rails, Django, Spring, Phoenix, Laravel, .NET).
- Boundaries via packages, not network hops.
- Background jobs in the same monolith with a queue worker.
- The "best speed-to-revenue" architecture for < 10 engineers.
11.3 · Modular monolith — the underrated middle
- One deployable. Strict internal modules with explicit APIs between them.
- If a module needs its own scale, lift it into a service later (cheap to do because boundaries were clean).
- Tools: Java modules / Kotlin Gradle subprojects / Rust workspaces / TS workspace + nx boundaries.
11.4 · Microservices — only when you need them
| Pro | Con |
|---|---|
| Independent deploys per team | Network + serialisation cost on every call |
| Tech polyglot | Operational footprint multiplies |
| Smaller blast radius | Distributed bugs are 10× harder |
| Scale per service | Need mesh, OTel, contracts to stay sane |
The bar
You should not pay the microservices tax until you have multiple teams whose release cadences actually
conflict. Conway's Law cuts both ways.
11.5 · BFF — Backend For Frontend
One backend per client surface (web, iOS, Android, partner). Each tailored to its consumer's needs — composing downstream services. Pairs well with GraphQL or tRPC.
11.6 · Service mesh — Istio, Linkerd, Consul, Cilium
- Sidecar proxy (Envoy) per pod, or sidecar-less (Cilium eBPF, Istio Ambient).
- Gives you uniformly: mTLS, retries, timeouts, circuit breaking, traffic shifting, telemetry.
- Cost: operational complexity. Pick a mesh once your service count is > ~10.
11.7 · Hexagonal / Clean / Onion architecture
Same idea, three names: core domain at the centre, surrounded by ports (interfaces) and adapters (DB, HTTP, queue). Lets you swap infrastructure without touching domain logic.
11.8 · DDD — bounded contexts
- Identify bounded contexts — each with its own ubiquitous language. "Order" in shipping ≠ "Order" in billing.
- Strategic patterns: partnership, customer–supplier, conformist, anti-corruption layer.
- Tactical patterns: entity, value object, aggregate, repository, domain event.
- Use DDD heavily when the domain is the hard part (insurance, lending, healthcare).
11.9 · CQRS & Event Sourcing
- CQRS: separate models (and possibly stores) for commands (writes) and queries (reads).
- 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 (finance, accounting, regulated workflows).
11.10 · Migration — strangler fig
- Route new traffic to the new service via a façade/proxy.
- Move features one by one; both old and new run in parallel.
- When the legacy has no traffic left, retire it.
The only sane way to evolve a monolith into services without a big-bang rewrite.
11.11 · Self-check
Q1 · A 6-engineer team building a new SaaS picks…
15 microservices
A modular monolith
A service mesh from day 1
CQRS + event sourcing