Home Cheat Sheets Microservices Cheat Sheet
📋 CHEAT SHEET

Microservices Cheat Sheet

Visual reference for microservices architecture — API gateway, services, message bus, per-service databases, service discovery and observability.

Core Patterns

PatternPurposeKey Rule
API GatewaySingle entry point for all clientsHandles auth, rate limiting, routing, SSL termination
Service per DatabaseEach service owns its data storeNo service directly queries another's DB
Event-Driven / Message BusAsync communication between servicesProducer emits events; consumers react independently
Service DiscoveryServices find each other dynamicallyClient-side (Eureka) or server-side (AWS ALB) lookup
Circuit BreakerPrevent cascade failuresOpen circuit after N failures; half-open to retry
Saga PatternDistributed transactions across servicesChoreography (events) or Orchestration (central coordinator)
Strangler FigMigrate monolith incrementallyRoute traffic to new services one feature at a time

Communication

TypeProtocolUse When
SynchronousREST / gRPC / GraphQLImmediate response required (queries, user-facing requests)
AsynchronousKafka / RabbitMQ / SQSFire-and-forget, eventual consistency acceptable
StreamingKafka / gRPC streamingContinuous data (logs, events, real-time pipelines)
Service MeshIstio / Linkerd (sidecar)mTLS, retries, observability without app code changes

Data Management

StrategyTrade-offPattern
Database per serviceNo shared stateEach service picks its own DB type (SQL, NoSQL, cache)
CQRSSeparate read/write modelsWrite to command store; project to read-optimised view
Event SourcingFull audit trail, replayableStore events not current state; rebuild from log
Shared cacheCross-service read speedRedis/Memcached for session, rate limits, hot data

Observability

PillarTool ExamplesWhat to Track
MetricsPrometheus + GrafanaRequest rate, error rate, latency (RED), CPU/memory (USE)
LogsELK Stack / LokiStructured JSON logs with correlation ID per request
TracesJaeger / Zipkin / OTELFull request path across services with span timings
Health checks/health, /ready endpointsLiveness (is it alive?) vs Readiness (can it serve traffic?)

Deployment Patterns

PatternRiskRollback
Blue-GreenLow — instant switchSwap traffic back to old environment
CanaryLow — gradual rolloutReduce canary weight to 0%
RollingMedium — mixed versions brieflyPause rollout, re-deploy old version
Feature FlagsLow — code ships darkToggle flag off instantly
A/B TestingLow — intentional splitRoute all to control variant

Security Patterns

PatternWhat It DoesTool / Standard
mTLS (mutual TLS)Both client and server authenticate with certificatesIstio, Linkerd — automatic in service mesh
JWT / OAuth2Stateless auth token passed in Authorization headerKeycloak, Auth0, AWS Cognito
API Gateway AuthValidate token once at gateway, forward identityKong, AWS API Gateway, Nginx
Secrets ManagementInject secrets at runtime, never bake into imagesHashiCorp Vault, AWS Secrets Manager, K8s Secrets
Zero-Trust NetworkingNever trust, always verify — even internal trafficNetwork policies + mTLS + RBAC
Rate LimitingProtect services from abuse and DDoSAPI Gateway, Redis token bucket, Envoy
Input ValidationValidate at each service boundary, not just gatewayNever assume upstream has sanitised input

Testing Strategies

LevelWhat to TestTool Examples
UnitBusiness logic in isolation, no I/OJUnit, pytest, Jest — mock all dependencies
IntegrationService + its own DB/cache/queueTestcontainers — spin up real dependencies
Contract (Consumer-Driven)API contract between consumer and providerPact — catch breaking changes before deploy
ComponentSingle service end-to-end with mocked downstreamWireMock, MockServer
E2EFull user journey across servicesPlaywright, Cypress, Postman/Newman — keep suite small
Chaos / ResilienceService behaviour under failure conditionsChaos Monkey, Gremlin, Toxiproxy
Performance / LoadThroughput, latency, autoscaling behaviourk6, Gatling, Locust
More Cheat Sheets
Java Collections Cheat SheetJava Streams API Cheat SheetPython Built-in Functions Cheat SheetSQL Joins Cheat SheetDocker Commands Cheat SheetJVM Memory Model DiagramHow HashMap Works InternallyPandas Cheat SheetData Structures & Algorithms Cheat Sheet