What is a Workflow?
A workflow is the top-level orchestration function that coordinates multiple steps, handles business logic, and can pause for extended periods using sleep or webhooks. Workflows are the entry point for your business processes.Key Characteristics
Durable
Workflows survive crashes, restarts, and deployments. State is preserved through event sourcing.
Suspendable
Workflows can pause for minutes, hours, or days without consuming resources.
Distributed
Workflows execute across Celery workers, enabling horizontal scaling.
Deterministic
Workflows can be replayed from any point using the recorded event log.
Creating Workflows
- Decorator
- Class
Configuration Options
- Decorator
- Class
| Option | Type | Default | Description |
|---|---|---|---|
name | str | Function/class name | Unique identifier for the workflow |
max_duration | str | "7d" | Maximum time the workflow can run |
max_retries | int | 0 | Number of times to retry the entire workflow |
Starting Workflows
Synchronous Start
Thestart() function dispatches a workflow to Celery and returns immediately:
With Idempotency Key
Prevent duplicate workflow executions:Workflow Lifecycle
Workflow Context
Inside a workflow, you can access the execution context:Error Handling
Workflows automatically handle errors based on their type:Best Practices
Keep workflows focused
Keep workflows focused
Each workflow should handle a single business process. If a workflow is getting complex, consider breaking it into smaller workflows that call each other.
Use meaningful names
Use meaningful names
Workflow names should clearly describe their purpose:
process_order, onboard_user, send_notification_sequence.Handle idempotency
Handle idempotency
Use idempotency keys for workflows that shouldn’t run twice for the same input. This prevents duplicate processing during retries.
Set appropriate timeouts
Set appropriate timeouts
Use
max_duration to prevent workflows from running indefinitely. Consider the longest possible execution path.