Skip to main content

Overview

PyWorkflow includes built-in safeguards to prevent runaway workflows from consuming excessive resources. These limits help ensure system stability and predictable behavior.

Event History Limits

Since PyWorkflow uses event sourcing, every workflow action is recorded as an event. To prevent unbounded growth and memory issues, there are limits on the number of events a workflow can generate.

Soft Limit (Warning)

When a workflow reaches 10,000 events, PyWorkflow logs a warning:
After the soft limit, warnings continue every 100 events (10,100, 10,200, etc.) to alert you that the workflow is growing large.

Hard Limit (Failure)

When a workflow reaches 50,000 events, it is terminated with an EventLimitExceededError:
The hard limit is a safety mechanism. If your workflow is hitting this limit, it likely indicates a design issue such as an infinite loop or processing too many items in a single workflow run.

Why These Limits Exist

  1. Memory Protection: Each event consumes memory. Unbounded event growth can exhaust system resources.
  2. Replay Performance: When workflows resume, all events are replayed. Large event logs slow down resumption.
  3. Storage Costs: Events are persisted to storage. Excessive events increase storage requirements.
  4. Bug Detection: Hitting limits often indicates bugs like infinite loops or improper workflow design.

Best Practices

Design for bounded event counts:

Configuring Limits

Modifying event limits is not recommended. The defaults are carefully chosen to balance flexibility with safety. Only change these if you fully understand the implications.
If you must change the limits:

Configuration Options

Transient Mode

Event limits only apply to durable workflows. Transient workflows (with durable=False) do not record events and are not subject to these limits.
Transient workflows sacrifice durability for performance. They cannot be resumed after crashes or restarts.

Monitoring Event Counts

You can monitor event counts using the storage backend:

Handling Limit Errors

When the hard limit is reached, an EventLimitExceededError is raised. This error inherits from FatalError, meaning it will not be retried.

Next Steps

Events

Learn how event sourcing works in PyWorkflow.

Configuration

See all available configuration options.