$npx -y skills add wshobson/agents --skill workflow-orchestration-patternsDesign durable workflows with Temporal for distributed systems. Covers workflow vs activity separation, saga patterns, state management, and determinism constraints. Use when building long-running processes, distributed transactions, or microservice orchestration.
| 1 | # Workflow Orchestration Patterns |
| 2 | |
| 3 | Master workflow orchestration architecture with Temporal, covering fundamental design decisions, resilience patterns, and best practices for building reliable distributed systems. |
| 4 | |
| 5 | ## When to Use Workflow Orchestration |
| 6 | |
| 7 | ### Ideal Use Cases (Source: docs.temporal.io) |
| 8 | |
| 9 | - **Multi-step processes** spanning machines/services/databases |
| 10 | - **Distributed transactions** requiring all-or-nothing semantics |
| 11 | - **Long-running workflows** (hours to years) with automatic state persistence |
| 12 | - **Failure recovery** that must resume from last successful step |
| 13 | - **Business processes**: bookings, orders, campaigns, approvals |
| 14 | - **Entity lifecycle management**: inventory tracking, account management, cart workflows |
| 15 | - **Infrastructure automation**: CI/CD pipelines, provisioning, deployments |
| 16 | - **Human-in-the-loop** systems requiring timeouts and escalations |
| 17 | |
| 18 | ### When NOT to Use |
| 19 | |
| 20 | - Simple CRUD operations (use direct API calls) |
| 21 | - Pure data processing pipelines (use Airflow, batch processing) |
| 22 | - Stateless request/response (use standard APIs) |
| 23 | - Real-time streaming (use Kafka, event processors) |
| 24 | |
| 25 | ## Detailed patterns and worked examples |
| 26 | |
| 27 | Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient. |
| 28 | |
| 29 | ## Best Practices |
| 30 | |
| 31 | ### Workflow Design |
| 32 | |
| 33 | 1. **Keep workflows focused** - Single responsibility per workflow |
| 34 | 2. **Small workflows** - Use child workflows for scalability |
| 35 | 3. **Clear boundaries** - Workflow orchestrates, activities execute |
| 36 | 4. **Test locally** - Use time-skipping test environment |
| 37 | |
| 38 | ### Activity Design |
| 39 | |
| 40 | 1. **Idempotent operations** - Safe to retry |
| 41 | 2. **Short-lived** - Seconds to minutes, not hours |
| 42 | 3. **Timeout configuration** - Always set timeouts |
| 43 | 4. **Heartbeat for long tasks** - Report progress |
| 44 | 5. **Error handling** - Distinguish retryable vs non-retryable |
| 45 | |
| 46 | ### Common Pitfalls |
| 47 | |
| 48 | **Workflow Violations**: |
| 49 | |
| 50 | - Using `datetime.now()` instead of `workflow.now()` |
| 51 | - Threading or async operations in workflow code |
| 52 | - Calling external APIs directly from workflow |
| 53 | - Non-deterministic logic in workflows |
| 54 | |
| 55 | **Activity Mistakes**: |
| 56 | |
| 57 | - Non-idempotent operations (can't handle retries) |
| 58 | - Missing timeouts (activities run forever) |
| 59 | - No error classification (retry validation errors) |
| 60 | - Ignoring payload limits (2MB per argument) |
| 61 | |
| 62 | ### Operational Considerations |
| 63 | |
| 64 | **Monitoring**: |
| 65 | |
| 66 | - Workflow execution duration |
| 67 | - Activity failure rates |
| 68 | - Retry attempts and backoff |
| 69 | - Pending workflow counts |
| 70 | |
| 71 | **Scalability**: |
| 72 | |
| 73 | - Horizontal scaling with workers |
| 74 | - Task queue partitioning |
| 75 | - Child workflow decomposition |
| 76 | - Activity batching when appropriate |
| 77 | |
| 78 | ## Additional Resources |
| 79 | |
| 80 | **Official Documentation**: |
| 81 | |
| 82 | - Temporal Core Concepts: docs.temporal.io/workflows |
| 83 | - Workflow Patterns: docs.temporal.io/evaluate/use-cases-design-patterns |
| 84 | - Best Practices: docs.temporal.io/develop/best-practices |
| 85 | - Saga Pattern: temporal.io/blog/saga-pattern-made-easy |
| 86 | |
| 87 | **Key Principles**: |
| 88 | |
| 89 | 1. Workflows = orchestration, Activities = external calls |
| 90 | 2. Determinism is non-negotiable for workflows |
| 91 | 3. Idempotency is critical for activities |
| 92 | 4. State preservation is automatic |
| 93 | 5. Design for failure and recovery |