$npx -y skills add tranhieutt/software_development_department --skill microservices-patternsProvides microservices design patterns for service decomposition, API gateway, circuit breakers, saga orchestration, and inter-service communication. Use when designing or implementing microservices architecture.
| 1 | # Microservices Patterns |
| 2 | |
| 3 | Service decomposition, communication, resilience, and orchestration patterns. |
| 4 | |
| 5 | ## Service Decomposition |
| 6 | |
| 7 | | Pattern | Description | Use When | |
| 8 | |---------|-------------|----------| |
| 9 | | Domain-Driven | Align services with bounded contexts | Complex business domains | |
| 10 | | Data-Ownership | Service owns its data store | Data isolation required | |
| 11 | | Team-Aligned | One service per team | Large organizations | |
| 12 | |
| 13 | ## Communication Patterns |
| 14 | |
| 15 | ### Sync: HTTP/gRPC |
| 16 | \`\`\`yaml |
| 17 | # API Gateway routing |
| 18 | routes: |
| 19 | - match: { prefix: /orders } |
| 20 | route: { cluster: order-service } |
| 21 | - match: { prefix: /users } |
| 22 | route: { cluster: user-service } |
| 23 | \`\`\` |
| 24 | |
| 25 | ### Async: Message Queue |
| 26 | \`\`\` |
| 27 | Producer → Exchange → Queue → Consumer |
| 28 | (Topic) (DLQ on failure) |
| 29 | \`\`\` |
| 30 | |
| 31 | Use async for: event propagation, eventual consistency, load leveling. |
| 32 | |
| 33 | ## Resilience Patterns |
| 34 | |
| 35 | ### Circuit Breaker |
| 36 | \`\`\`typescript |
| 37 | // Example with opossum |
| 38 | const breaker = new CircuitBreaker(fetchUserProfile, { |
| 39 | timeout: 3000, |
| 40 | errorThresholdPercentage: 50, |
| 41 | resetTimeout: 30000, |
| 42 | }); |
| 43 | \`\`\` |
| 44 | |
| 45 | ### Retry with Backoff |
| 46 | \`\`\`typescript |
| 47 | async function retryWithBackoff(fn, maxRetries = 3) { |
| 48 | for (let i = 0; i < maxRetries; i++) { |
| 49 | try { return await fn(); } |
| 50 | catch (e) { await sleep(Math.pow(2, i) * 1000); } |
| 51 | } |
| 52 | throw new Error('Max retries exceeded'); |
| 53 | } |
| 54 | \`\`\` |
| 55 | |
| 56 | ## Data Patterns |
| 57 | |
| 58 | | Pattern | Consistency | Complexity | Use When | |
| 59 | |---------|-------------|------------|----------| |
| 60 | | Saga (orchestration) | Eventual | High | Complex multi-service transactions | |
| 61 | | Saga (choreography) | Eventual | Medium | Simple event chains | |
| 62 | | Event sourcing | Eventual | High | Audit trail, time travel | |
| 63 | | Shared database | Strong | Low | Anti-pattern, avoid | |
| 64 | |
| 65 | ## API Gateway |
| 66 | |
| 67 | Tools: Kong, AWS API Gateway, Envoy, NGINX. |
| 68 | |
| 69 | Responsibilities: routing, auth, rate limiting, request transformation, load balancing. |
| 70 | |
| 71 | ## Observability Stack |
| 72 | |
| 73 | - Distributed tracing: Jaeger / Tempo |
| 74 | - Metrics: Prometheus + Grafana |
| 75 | - Logs: ELK / Loki |
| 76 | - Service mesh: Istio / Linkerd (adds mTLS, traffic management) |
| 77 | |
| 78 | ## Related Skills |
| 79 | |
| 80 | - `backend-architect` — single-service architecture |
| 81 | - `event-sourcing-architect` — event sourcing patterns |
| 82 | - `kubernetes-architect` — deployment patterns |
| 83 | - `deployment-engineer` — CI/CD for microservices |