Skip to main content

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

Configuration Options

Starting Workflows

Synchronous Start

The start() function dispatches a workflow to Celery and returns immediately:

With Idempotency Key

Prevent duplicate workflow executions:

Workflow Lifecycle

When a worker crashes, the workflow enters INTERRUPTED status and automatically recovers on another worker. See Fault Tolerance for details.

Workflow Context

Inside a workflow, you can access the execution context:

Error Handling

Workflows automatically handle errors based on their type:

Best Practices

Each workflow should handle a single business process. If a workflow is getting complex, consider breaking it into smaller workflows that call each other.
Workflow names should clearly describe their purpose: process_order, onboard_user, send_notification_sequence.
Use idempotency keys for workflows that shouldn’t run twice for the same input. This prevents duplicate processing during retries.
Use max_duration to prevent workflows from running indefinitely. Consider the longest possible execution path.
Enable recover_on_worker_loss for critical workflows to ensure automatic recovery from worker crashes. See Fault Tolerance for configuration options.

Next Steps

Steps

Learn about steps - the building blocks of workflows.

Step Context

Share typed context data with distributed steps.

Schedules

Automatically run workflows on cron, interval, or calendar schedules.

Fault Tolerance

Configure auto recovery from worker crashes.