Workflow orchestration patterns

From sinhoneyy/master-skills · View interactive version

Workflow orchestration patterns is an AI agent skill from the GitHub repository sinhoneyy/master-skills. Master workflow orchestration architecture with Temporal, covering fundamental design decisions, resilience patterns, and best practices for building reliable distributed systems.

How to use this skill

Skill file

Workflow Orchestration Patterns

Master workflow orchestration architecture with Temporal, covering fundamental design decisions, resilience patterns, and best practices for building reliable distributed systems.

Use this skill when

Do not use this skill when

Instructions

When to Use Workflow Orchestration

Ideal Use Cases (Source: docs.temporal.io)

When NOT to Use

Critical Design Decision: Workflows vs Activities

The Fundamental Rule (Source: temporal.io/blog/workflow-engine-principles):

Workflows (Orchestration)

Characteristics:

Example workflow tasks:

Activities (External Interactions)

Characteristics:

Example activity tasks:

Design Decision Framework

Does it touch external systems? → Activity
Is it orchestration/decision logic? → Workflow

Core Workflow Patterns

1. Saga Pattern with Compensation

Purpose: Implement distributed transactions with rollback capability

Pattern (Source: temporal.io/blog/compensating-actions-part-of-a-complete-breakfast-with-sagas):

For each step:
  1. Register compensation BEFORE executing
  2. Execute the step (via activity)
  3. On failure, run all compensations in reverse order (LIFO)

Example: Payment Workflow

  1. Reserve inventory (compensation: release inventory)
  2. Charge payment (compensation: refund payment)
  3. Fulfill order (compensation: cancel fulfillment)

Critical Requirements:

2. Entity Workflows (Actor Model)

Purpose: Long-lived workflow representing single entity instance

Pattern (Source: docs.temporal.io/evaluate/use-cases-design-patterns):

Example Use Cases:

Benefits:

3. Fan-Out/Fan-In (Parallel Execution)

Purpose: Execute multiple tasks in parallel, aggregate results

Pattern:

Scaling Rule (Source: temporal.io/blog/workflow-engine-principles):

4. Async Callback Pattern

Purpose: Wait for external event or human approval

Pattern:

Use Cases:

State Management and Determinism

Automatic State Preservation

How Temporal Works (Source: docs.temporal.io/workflows):

Determinism Constraints

Workflows Execute as State Machines:

Prohibited in Workflows (Source: docs.temporal.io/workflows):

Allowed in Workflows:

Versioning Strategies

Challenge: Changing workflow code while old executions still running

Solutions:

  1. Versioning API: Use workflow.get_version() for safe changes
  2. New Workflow Type: Create new workflow, route new executions to it
  3. Backward Compatibility: Ensure old events replay correctly

Resilience and Error Handling

Retry Policies

Default Behavior: Temporal retries activities forever

Configure Retry:

Non-Retryable Errors:

Idempotency Requirements

Why Critical (Source: docs.temporal.io/activities):

Implementation Strategies:

Activity Heartbeats

Purpose: Detect stalled long-running activities

Pattern:

Best Practices

Workflow Design

  1. Keep workflows focused - Single responsibility per workflow
  2. Small workflows - Use child workflows for scalability
  3. Clear boundaries - Workflow orchestrates, activities execute
  4. Test locally - Use time-skipping test environment

Activity Design

  1. Idempotent operations - Safe to retry
  2. Short-lived - Seconds to minutes, not hours
  3. Timeout configuration - Always set timeouts
  4. Heartbeat for long tasks - Report progress
  5. Error handling - Distinguish retryable vs non-retryable

Common Pitfalls

Workflow Violations:

Activity Mistakes:

Operational Considerations

Monitoring:

Scalability:

Additional Resources

Official Documentation:

Key Principles:

  1. Workflows = orchestration, Activities = external calls
  2. Determinism is non-negotiable for workflows
  3. Idempotency is critical for activities
  4. State preservation is automatic
  5. Design for failure and recovery

Limitations

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.