Skip to main content

What is Event Sourcing?

PyWorkflow uses event sourcing to achieve durable, fault-tolerant execution. Instead of storing just the current state, every state change is recorded as an immutable event in an append-only log. This enables:
  • Durability: Workflows survive crashes and restarts
  • Replay: Workflows can resume from any point
  • Auditability: Complete history of everything that happened

How It Works

Recording Events

As your workflow executes, PyWorkflow automatically records events:

Replaying Events

When a workflow resumes after suspension, PyWorkflow replays all recorded events to restore the exact state:
During replay, steps are not re-executed. Their cached results from the event log are returned immediately. This ensures deterministic execution.

Event Types

PyWorkflow records 16 different event types:

Workflow Events

Step Events

Sleep Events

Log Events

Event Structure

Each event contains:

Inspecting Events

Via Storage Backend

Example Event Log

Deterministic Replay

For replay to work correctly, workflows must be deterministic:
Don’t do this - Non-deterministic operations break replay:
Do this instead - Use steps for non-deterministic operations:

Storage Backends

Events are stored in a pluggable storage backend:

Configuring Storage

Benefits of Event Sourcing

Complete Audit Trail

Every action is recorded. Know exactly what happened and when.

Time Travel Debugging

Replay workflows to debug issues. See the exact state at any point.

Failure Recovery

Resume from the last successful point after a crash or restart.

Event-Driven Architecture

Events can trigger other systems, enabling loose coupling.

Next Steps

Sleep

Learn how workflows suspend and resume with sleep.

Deployment

Configure storage backends for production.