$npx -y skills add Jeffallan/claude-skills --skill microservices-architectDesigns distributed system architectures, decomposes monoliths into bounded-context services, recommends communication patterns, and produces service boundary diagrams and resilience strategies. Use when designing distributed systems, decomposing monoliths, or implementing micros
| 1 | # Microservices Architect |
| 2 | |
| 3 | Senior distributed systems architect specializing in cloud-native microservices architectures, resilience patterns, and operational excellence. |
| 4 | |
| 5 | ## Core Workflow |
| 6 | |
| 7 | 1. **Domain Analysis** — Apply DDD to identify bounded contexts and service boundaries. |
| 8 | - *Validation checkpoint:* Each candidate service owns its data exclusively, has a clear public API contract, and can be deployed independently. |
| 9 | 2. **Communication Design** — Choose sync/async patterns and protocols (REST, gRPC, events). |
| 10 | - *Validation checkpoint:* Long-running or cross-aggregate operations use async messaging; only query/command pairs with sub-100 ms SLA use synchronous calls. |
| 11 | 3. **Data Strategy** — Database per service, event sourcing, eventual consistency. |
| 12 | - *Validation checkpoint:* No shared database schema exists between services; consistency boundaries align with bounded contexts. |
| 13 | 4. **Resilience** — Circuit breakers, retries, timeouts, bulkheads, fallbacks. |
| 14 | - *Validation checkpoint:* Every external call has an explicit timeout, retry budget, and graceful degradation path. |
| 15 | 5. **Observability** — Distributed tracing, correlation IDs, centralized logging. |
| 16 | - *Validation checkpoint:* A single request can be traced end-to-end using its correlation ID across all services. |
| 17 | 6. **Deployment** — Container orchestration, service mesh, progressive delivery. |
| 18 | - *Validation checkpoint:* Health and readiness probes are defined; canary or blue-green rollout strategy is documented. |
| 19 | |
| 20 | ## Reference Guide |
| 21 | |
| 22 | Load detailed guidance based on context: |
| 23 | |
| 24 | | Topic | Reference | Load When | |
| 25 | |-------|-----------|-----------| |
| 26 | | Service Boundaries | `references/decomposition.md` | Monolith decomposition, bounded contexts, DDD | |
| 27 | | Communication | `references/communication.md` | REST vs gRPC, async messaging, event-driven | |
| 28 | | Resilience Patterns | `references/patterns.md` | Circuit breakers, saga, bulkhead, retry strategies | |
| 29 | | Data Management | `references/data.md` | Database per service, event sourcing, CQRS | |
| 30 | | Observability | `references/observability.md` | Distributed tracing, correlation IDs, metrics | |
| 31 | |
| 32 | ## Implementation Examples |
| 33 | |
| 34 | ### Correlation ID Middleware (Node.js / Express) |
| 35 | ```js |
| 36 | const { v4: uuidv4 } = require('uuid'); |
| 37 | |
| 38 | function correlationMiddleware(req, res, next) { |
| 39 | req.correlationId = req.headers['x-correlation-id'] || uuidv4(); |
| 40 | res.setHeader('x-correlation-id', req.correlationId); |
| 41 | // Attach to logger context so every log line includes the ID |
| 42 | req.log = logger.child({ correlationId: req.correlationId }); |
| 43 | next(); |
| 44 | } |
| 45 | ``` |
| 46 | Propagate `x-correlation-id` in every outbound HTTP call and Kafka message header. |
| 47 | |
| 48 | ### Circuit Breaker (Python / `pybreaker`) |
| 49 | ```python |
| 50 | import pybreaker |
| 51 | |
| 52 | # Opens after 5 failures; resets after 30 s in half-open state |
| 53 | breaker = pybreaker.CircuitBreaker(fail_max=5, reset_timeout=30) |
| 54 | |
| 55 | @breaker |
| 56 | def call_inventory_service(order_id: str): |
| 57 | response = requests.get(f"{INVENTORY_URL}/stock/{order_id}", timeout=2) |
| 58 | response.raise_for_status() |
| 59 | return response.json() |
| 60 | |
| 61 | def get_inventory(order_id: str): |
| 62 | try: |
| 63 | return call_inventory_service(order_id) |
| 64 | except pybreaker.CircuitBreakerError: |
| 65 | return {"status": "unavailable", "fallback": True} |
| 66 | ``` |
| 67 | |
| 68 | ### Saga Orchestration Skeleton (TypeScript) |
| 69 | ```ts |
| 70 | // Each step defines execute() and compensate() so rollback is automatic. |
| 71 | interface SagaStep<T> { |
| 72 | execute(ctx: T): Promise<T>; |
| 73 | compensate(ctx: T): Promise<void>; |
| 74 | } |
| 75 | |
| 76 | async function runSaga<T>(steps: SagaStep<T>[], initialCtx: T): Promise<T> { |
| 77 | const completed: SagaStep<T>[] = []; |
| 78 | let ctx = initialCtx; |
| 79 | for (const step of steps) { |
| 80 | try { |
| 81 | ctx = await step.execute(ctx); |
| 82 | completed.push(step); |
| 83 | } catch (err) { |
| 84 | for (const done of completed.reverse()) { |
| 85 | await done.compensate(ctx).catch(console.error); |
| 86 | } |
| 87 | throw err; |
| 88 | } |
| 89 | } |
| 90 | return ctx; |
| 91 | } |
| 92 | |
| 93 | // Usage: order creation saga |
| 94 | const orderSaga = [reserveInventoryStep, chargePaymentStep, scheduleShipmentStep]; |
| 95 | await runSaga(orderSaga, { orderId, customerId, items }); |
| 96 | ``` |