Key Terms
| Term | In one line |
|---|---|
| Bounded context | The boundary within which a model and its language are unambiguous |
| Aggregate root | The only permitted entry point into a cluster of objects that change together |
| Anti-corruption layer | Translation that stops a legacy or foreign model leaking into yours |
| Strangler fig | Migration pattern — route slices to the new system until the old one is dead |
| Distributed monolith | Separately deployed services that must still release together — worst of both |
| Saga | Long-running transaction as a sequence of local transactions plus compensations |
| Choreography vs orchestration | Services react to events / a coordinator drives the flow |
| Outbox | Write the event to a table in the same transaction as the state change, publish after — solves dual-write |
| CDC | Change Data Capture — stream committed DB changes (Debezium) |
| CRDT | Data types that merge concurrent writes deterministically, no coordination |
| DLQ | Where poison messages go so they stop blocking the queue |
Numbers That Matter
| Figure | Value | Where it bites |
|---|---|---|
| Richardson maturity | L0 POX → L1 resources → L2 verbs+status → L3 HATEOAS | Most real APIs are L2 and that’s fine — say so |
| Status codes | 200 · 201 created · 204 no content · 400 · 401 unauthenticated · 403 unauthorized · 404 · 409 conflict · 422 · 429 · 503 | 401 vs 403 is the classic trip |
| 12-factor | 12 | Config in environment, stateless processes, logs as streams |
| Async default | ~80% async over sync | The target ratio for avoiding a distributed monolith |
Decision Rules
- Decompose by business capability first, subdomain (DDD) second. Never by technical layer, and never before you understand the domain — premature decomposition creates permanent boundary rework.
- Don’t use microservices when the team is small, the domain is poorly understood, or the deployment/operational maturity isn’t there. A well-structured modular monolith beats thirty services nobody can trace.
- Six anti-patterns to name: distributed monolith, chatty synchronous chains, shared database, no gateway, premature decomposition, nanoservices, entangled lifecycle via a shared business-logic library.
- gRPC vs REST vs GraphQL: gRPC for internal high-throughput, typed, low-latency service-to-service. REST for public, cacheable, universally consumable APIs. GraphQL when clients need to shape varied queries and over-fetching is the actual problem — at the cost of caching and rate-limiting complexity.
- Choreography when the flow is simple and services are genuinely independent; orchestration when you need to see the flow, handle complex compensation, or explain it to auditors. Choreography’s cost is that nobody can find the process.
- Outbox over dual-write, always. Writing to the database and publishing to the broker in two steps has no atomic guarantee — the outbox table plus a relay (or CDC) does.
- 2PC vs saga: 2PC gives real atomicity and blocks on the coordinator — acceptable inside one trust boundary, not across services. Sagas give eventual consistency with explicit compensations, which is why you need to design the undo for every step.
- Idempotency keys on every non-idempotent public endpoint. Clients will retry; the network guarantees it.
Say This Out Loud
“The failure I look for first is a distributed monolith — services deployed separately but so contractually coupled that they still have to release together. You’ve paid every cost of distribution and collected none of the benefit. The tells are a shared database, synchronous call chains four services deep, and a shared business-logic library that forces a coordinated release for a one-line fix.”
“For a state change that has to produce an event, I use the outbox pattern rather than writing to the database and then publishing. Dual-write has no atomicity — if the broker publish fails after the commit, you have state with no event, and if it succeeds and the commit doesn’t, you have an event for something that never happened. The outbox writes the event into a table inside the same transaction, and a relay or CDC publishes it afterwards. It’s at-least-once, so consumers have to be idempotent, and that’s a trade I’ll take every time.”
“I’d choose orchestration over choreography once compensation gets non-trivial. Choreography is elegant and genuinely decoupled, but the process doesn’t exist anywhere — it’s emergent, and when a saga half-completes at two in the morning nobody can tell you what state it’s in. An orchestrator is a single place the flow is written down, which matters for debugging and matters even more for auditors.”