Skip to main content

What is Fault Tolerance?

In distributed systems, workers can fail unexpectedly due to crashes, OOM kills, network issues, or deployments. PyWorkflow’s fault tolerance ensures your workflows survive these failures and automatically resume from where they left off.

Automatic Detection

Worker crashes are detected automatically when Celery requeues tasks.

Event Replay

Completed steps are restored from the event log without re-execution.

Checkpoint Resume

Workflows continue from the last successful checkpoint, not from the beginning.

Configurable Limits

Control recovery attempts and behavior per workflow or globally.

How Auto Recovery Works

When a worker crashes mid-workflow, PyWorkflow automatically recovers:
The key insight is that event sourcing makes recovery possible. All completed steps are recorded as events, so on recovery, PyWorkflow simply replays those events to restore the workflow’s state without re-executing any work.

Configuration

Configure recovery per-workflow using the @workflow decorator:

Configuration Options

Configuration Priority

When resolving recovery settings, PyWorkflow uses this priority order:

Durable vs Transient Workflows

Recovery behavior differs based on workflow durability:
Durable workflows resume from the last checkpoint.
Recovery process:
  1. Load event log from storage
  2. Replay step_completed events (restore cached results)
  3. Complete pending sleep_started events
  4. Continue execution from the next step

Workflow States

Auto recovery introduces a new workflow state:

Monitoring Recovery

Use the CLI to monitor workflows that have been interrupted or recovered:
Example output:

When to Disable Recovery

If your workflow makes calls that can’t be safely repeated (e.g., charging a credit card without idempotency keys), disable recovery or implement compensation logic.
Some workflows should fail loudly and require human intervention rather than automatic recovery.
If your workflow interacts with systems that don’t support rollback or compensation, partial re-execution could leave inconsistent state.

Best Practices

Design steps to produce the same result when called multiple times with the same input. Use idempotency keys for external API calls.
Don’t allow unlimited recovery attempts. Set max_recovery_attempts based on your tolerance for repeated failures.
Set up alerts for workflows that reach INTERRUPTED status frequently. This may indicate infrastructure issues.
Critical business workflows should always use durable mode to ensure proper recovery.

Next Steps

Workflows

Learn about workflow lifecycle and configuration.

Events

Understand the event sourcing model that enables recovery.

Configuration

Configure fault tolerance settings globally.

CLI Guide

Monitor and manage workflows from the command line.