Designing Microservices Architecture

1. Decomposing Monoliths into Microservices

StepAction
Identify seamsBounded contexts, cohesive modules
Extract moduleModular monolith first
DB extractionSchema split, then physical DB
Strangler facadeRoute traffic to new service
Decommission legacyRemove old code paths

2. Designing Service Discovery

MechanismTool
Client-sideEureka, Consul
Server-side (LB)K8s Service, AWS ALB
DNS-basedK8s CoreDNS, Route53
Service meshIstio, Linkerd, Consul Connect

3. Designing API Gateway Pattern

FunctionTool
Single entryKong, Envoy, Apigee, AWS API GW
AuthN/ZJWT, OIDC at edge
AggregationBFF pattern
ObservabilityCentralized metrics + traces

4. Designing Inter-Service Communication

PatternUse Case
Sync HTTP/RESTSimple, debug-friendly
Sync gRPCLow-latency, typed
Async events (Kafka, NATS)Decoupled, resilient
Async commands (RabbitMQ, SQS)Work queues
Choreography vs orchestrationDistributed control vs central

5. Designing Service Mesh

CapabilityDescription
mTLSAuto-issued cert per pod
Traffic shiftingCanary, mirror, fault injection
Retries / timeoutsDeclarative per route
ObservabilityL7 metrics + tracing automatic
ToolsIstio, Linkerd, Consul, Kuma, Cilium

6. Designing Distributed Tracing Architecture

ComponentDetail
SpecOpenTelemetry, W3C traceparent
CollectorOTel Collector → backend
BackendJaeger, Tempo, Honeycomb, Datadog
SamplingHead-based or tail-based (1–10%)
Trace ID propagationThrough all hops + queues

7. Designing Circuit Breaker Pattern

    Closed ──fail rate > threshold──▶ Open
       ▲                                │
       │ success                        │ wait timeout
       │                                ▼
   Half-Open ◀──── probe call ────── Open
      
StateBehavior
ClosedAll calls pass; track failures
OpenFail fast; no calls reach service
Half-OpenAllow few probes; close on success
LibraryResilience4j, Polly, Hystrix (legacy)

8. Designing Service Versioning Strategy

ApproachDetail
SemVerMajor.Minor.Patch
Side-by-side deployv1 and v2 both running
Header routingX-Service-Version
Contract testsPact between consumers and producer

9. Designing Saga Pattern for Distributed Transactions

TypeCoordination
ChoreographyServices react to events
OrchestrationCentral orchestrator (Temporal, Camunda)
CompensationInverse step on failure
IdempotencyRequired for retries

10. Designing Bounded Contexts

Service Boundary HeuristicDetail
Single team owns2-pizza team
Independent deployDaily cadence
Owns its dataNo shared DB
Cohesive domainOne ubiquitous language

11. Designing Microservices Data Management

PatternDetail
DB per serviceNo shared DBs
Event-carried state transferReplicate needed data via events
CQRSRead model in consumer service
Outbox patternAtomic state + event publish
SagaCross-service workflows

12. Designing Microservices Testing Strategy

LayerTest
UnitDomain logic, fast
IntegrationService + DB (Testcontainers)
ContractPact, consumer-driven
ComponentService isolated, deps mocked
End-to-endFew critical journeys
ChaosFailure injection in staging/prod