contentintech

Microservices Cheatsheet

Quick reference for microservices decomposition, communication, resilience patterns, and distributed transactions.

DDDService MeshSagaResilience
NotesCheatsheet

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

MonolithMicroservices
In-process callsNetwork calls
ACID txnsSagas / eventual
Scale whole appScale hot services
One deployPer-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

StyleUse
RESTPublic APIs, CRUD
gRPCInternal, low-latency, streaming
EventsDecouple, 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

ApproachNote
2PCBlocking, avoid
Saga choreographyEvent-driven, implicit flow
Saga orchestrationCentral brain, observable
Outbox + CDCAtomic 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 traceparent correlation 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.

Section navigation