Microservice Patterns

hub

Communication Patterns

API Gateway

Single entry point for all clients, routing requests to appropriate microservices with cross-cutting concerns like auth and rate limiting.

Key Features
  • Request routing and composition
  • Authentication and authorization
  • Rate limiting and throttling
  • Response aggregation
Use Cases
  • Kong API Gateway
  • AWS API Gateway
  • Azure API Management
  • Netflix Zuul/Spring Cloud Gateway
Service Discovery

Automatic detection of service instances and their network locations, enabling dynamic service registration and lookup.

Key Features
  • Service registration
  • Health checking
  • Load balancing integration
  • Dynamic DNS resolution
Use Cases
  • Consul for service mesh
  • Eureka for Spring Cloud
  • etcd for Kubernetes
  • ZooKeeper coordination
Choreography

Decentralized service coordination where each service produces and consumes events independently without central orchestrator.

Key Features
  • Event-driven communication
  • Loose coupling between services
  • Autonomous service decisions
  • Event bus or message broker
Use Cases
  • Order processing workflows
  • Event-driven microservices
  • Reactive architectures
  • Domain event handling
Orchestration

Centralized coordinator controls the workflow, explicitly defining the sequence and logic of service interactions.

Key Features
  • Central workflow engine
  • Explicit service sequencing
  • Transaction coordination
  • Compensation handling
Use Cases
  • Order fulfillment workflows
  • Business process automation
  • Multi-step transactions
  • Temporal.io workflows
database

Data Management Patterns

CQRS (Command Query Responsibility Segregation)

Separates read and write operations into different models, optimizing each for their specific use case and scalability needs.

Key Features
  • Separate read and write models
  • Optimized query performance
  • Event sourcing integration
  • Eventual consistency handling
Use Cases
  • E-commerce product catalogs
  • Financial transaction systems
  • High-traffic dashboards
  • Audit-heavy applications
Event Sourcing

Stores all state changes as a sequence of events rather than current state, providing complete audit trail and time-travel capabilities.

Key Features
  • Immutable event log
  • Event replay capability
  • Temporal queries
  • Complete audit history
Use Cases
  • Banking transaction history
  • Version control systems
  • Order state transitions
  • CQRS implementations
Saga Pattern

Manages distributed transactions across microservices using compensating transactions to maintain data consistency.

Key Features
  • Choreography or orchestration based
  • Compensating transactions
  • Long-running transactions
  • Eventual consistency guarantee
Use Cases
  • Order and payment processing
  • Travel booking systems
  • Multi-step workflows
  • Distributed rollback scenarios
Database per Service

Each microservice has its own private database, ensuring loose coupling and independent deployment and scaling.

Key Features
  • Data encapsulation
  • Independent schema evolution
  • Technology diversity
  • Failure isolation
Use Cases
  • Polyglot persistence
  • Service autonomy
  • Independent scaling
  • Domain-driven design
shield

Resilience Patterns

Circuit Breaker

Prevents cascading failures by failing fast when a service is unavailable, with automatic recovery detection.

Key Features
  • Open/closed/half-open states
  • Failure threshold monitoring
  • Automatic recovery attempts
  • Fallback responses
Use Cases
  • Inter-service communication
  • External API calls
  • Database connection failures
  • Third-party integrations
Retry Pattern

Automatically retries failed operations with exponential backoff and jitter to handle transient failures.

Key Features
  • Configurable retry attempts
  • Exponential backoff strategy
  • Jitter for thundering herd prevention
  • Idempotency requirements
Use Cases
  • Network request failures
  • Temporary service unavailability
  • Message delivery
  • API rate limit handling
Bulkhead Pattern

Isolates resources into pools to prevent complete system failure when one resource is exhausted.

Key Features
  • Resource pool isolation
  • Thread pool separation
  • Connection pool partitioning
  • Blast radius limitation
Use Cases
  • Critical vs non-critical requests
  • Multi-tenant isolation
  • Service tier separation
  • Resource quota enforcement
Health Check

Monitors service health with liveness and readiness probes for automated recovery and load balancing decisions.

Key Features
  • Liveness probe (is running)
  • Readiness probe (can serve traffic)
  • Dependency health checks
  • Graceful degradation
Use Cases
  • Kubernetes probes
  • Load balancer decisions
  • Auto-scaling triggers
  • Service mesh integration
settings

Cross-Cutting Concerns

Distributed Tracing

Tracks requests across multiple microservices, providing visibility into distributed system behavior and performance.

Key Features
  • Request correlation IDs
  • Span and trace collection
  • Performance bottleneck detection
  • Service dependency mapping
Use Cases
  • Jaeger distributed tracing
  • Zipkin monitoring
  • AWS X-Ray
  • OpenTelemetry integration
Centralized Logging

Aggregates logs from all microservices into a central location for searching, analysis, and troubleshooting.

Key Features
  • Log aggregation and indexing
  • Correlation ID tracking
  • Real-time log streaming
  • Search and analytics
Use Cases
  • ELK Stack (Elasticsearch, Logstash, Kibana)
  • Splunk aggregation
  • CloudWatch Logs
  • Datadog logging
API Versioning

Manages multiple API versions simultaneously to support backward compatibility and gradual client migration.

Key Features
  • URI versioning (/v1/resource)
  • Header-based versioning
  • Backward compatibility
  • Gradual deprecation
Use Cases
  • Public API evolution
  • Mobile app compatibility
  • Third-party integrations
  • Breaking change management
Service Mesh

Infrastructure layer handling service-to-service communication with traffic management, security, and observability.

Key Features
  • Automatic mTLS encryption
  • Traffic routing and splitting
  • Load balancing
  • Distributed tracing integration
Use Cases
  • Istio service mesh
  • Linkerd lightweight mesh
  • Consul Connect
  • AWS App Mesh