Core Idea
Independently deployable services, each owning one business capability and its own data. The defining trait is independent deployability, not size. Trades local complexity for distributed complexity.
Distributed monolith
If you must deploy services together, you have the worst of both. Fix the coupling first.
Monolith vs Micro
| Monolith | Microservices |
|---|---|
| In-process calls | Network calls |
| ACID txns | Sagas / eventual |
| Scale whole app | Scale hot services |
| One deploy | Per-service deploys |
Decomposition
DDD boundaries
- Split by bounded context / business capability, never by tech layer.
- High cohesion inside, loose coupling between.
- Change together = belong together.
- Vertical slices:
orders,payments,inventory.
Communication
| Style | Use |
|---|---|
| REST | Public APIs, CRUD |
| gRPC | Internal, low-latency, streaming |
| Events | Decouple, workflows, fan-out |
Sync = temporal coupling. Prefer async events for cross-service workflows.
Infra Pieces
- API gateway — single entry: TLS, auth, routing, rate limit, aggregation.
- Discovery — client-side (client picks) vs server-side (LB picks).
- Registry — Consul / etcd / Eureka / k8s control plane.
- Service mesh — Envoy sidecar + Istio/Linkerd: mTLS, retries, telemetry out of code.
Resilience Patterns
- Timeout — never wait forever.
- Retry — backoff + jitter, idempotent only.
- Circuit breaker — closed / open / half-open, fail fast.
- Bulkhead — isolate pools per dependency.
- Rate limit / shed — reject excess load.
- Fallback — degrade gracefully.
Distributed Txns
| Approach | Note |
|---|---|
| 2PC | Blocking, avoid |
| Saga choreography | Event-driven, implicit flow |
| Saga orchestration | Central brain, observable |
| Outbox + CDC | Atomic DB write + publish |
DB-per-service is mandatory. Compensate on failure; consistency is eventual.
Observability
- Logs — structured, centralized, trace-stamped.
- Metrics — RED: Rate, Errors, Duration.
- Traces — OpenTelemetry spans end-to-end.
- Propagate
traceparentcorrelation ID on every hop.
Deploy & When Not To
Container + k8s. Rolling / blue-green / canary. Externalize config (ConfigMaps, Secrets).
Don't
Small team, fuzzy domain, no CI/CD or observability, early pivoting product. Use a modular monolith. Remember the 8 fallacies of distributed computing.