Guide the planning of microservices architecture. Use when designing, planning, or architecting a system using microservices.
Guided workflow for planning and designing microservices architecture.
Identify Bounded Contexts
Map Service Boundaries
┌─────────────────┐ ┌─────────────────┐
│ User Service │ │ Order Service │
│ │ │ │
│ • Registration │ │ • Cart │
│ • Authentication│ │ • Checkout │
│ • Profile │ │ • Order history │
└─────────────────┘ └─────────────────┘
│ │
└──────┬─────────────┘
▼
┌─────────────────────────────────┐
│ Notification Service │
│ │
│ • Email │
│ • SMS │
│ • Push notifications │
└─────────────────────────────────┘
Apply Single Responsibility
| Use When | Avoid When |
|---|---|
| Need immediate response | High latency tolerance |
| Simple request-response | Fan-out to many services |
| Read operations | Long-running operations |
| Use When | Avoid When |
|---|---|
| Eventual consistency OK | Immediate consistency required |
| Decoupling needed | Simple request-response |
| Fan-out to multiple services | Low complexity |
┌──────────────┐ publish ┌─────────────────┐
│ Order Service│ ──────────────▶│ Event Bus │
└──────────────┘ OrderCreated └─────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Inventory │ │ Notification │ │ Analytics │
│ Service │ │ Service │ │ Service │
└──────────────┘ └──────────────┘ └──────────────┘
| Pattern | Use Case |
|---|---|
| Saga | Distributed transactions |
| CQRS | Read/write separation |
| Event Sourcing | Audit trail, temporal queries |
Order Saga:
1. Order Service → Create order (PENDING)
2. Payment Service → Charge payment
├── Success → Continue
└── Failure → Compensate: Cancel order
3. Inventory Service → Reserve items
├── Success → Continue
└── Failure → Compensate: Refund, Cancel order
4. Order Service → Confirm order (CONFIRMED)
const circuitBreaker = new CircuitBreaker({
failureThreshold: 5, // Open after 5 failures
successThreshold: 3, // Close after 3 successes
timeout: 30000, // Half-open after 30s
fallback: () => cachedResponse
})
const result = await circuitBreaker.execute(() =>
externalService.call()
)
const retryConfig = {
maxRetries: 3,
baseDelay: 1000,
maxDelay: 10000,
exponential: true,
jitter: true
}
# Kubernetes Service
apiVersion: v1