Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

Workflow Step Execution, Events, Rollback and Instance Limits

How Cloudflare Workflows run durable steps, wait for events, retry and roll back, plus limits, billing, and how to verify instances.

This page summarizes Cloudflare Workflows documentation: durable, multi-step programs on the Workers platform that persist state, retry failed work, pause for hours or days, and coordinate external APIs without you managing orchestration infrastructure.

Build durable multi-step applications on Cloudflare Workers with Workflows.

— Cloudflare, Cloudflare Workflows

A Workflow is a named class (extending WorkflowEntrypoint) whose run method chains steps—self-contained, individually retryable units. Cloudflare describes this as Durable Execution: the runtime implicitly persists state so an instance can resume after interruption instead of you serializing everything to an external store.

Workflows allow you to build durable, multi-step applications using the Workers platform. A Workflow can automatically retry, persist state, run for hours or days, and coordinate between third-party APIs.

— Cloudflare, Build your first Workflow

Typical uses in the docs include post-processing R2 uploads, RAG pipelines, user lifecycle email, batch jobs, and human-in-the-loop approvals. Workflows is Generally Available for production workloads on Free and Paid Workers plans.

step.do: durable steps and when to split work

Section titled “step.do: durable steps and when to split work”

The step object is the core API inside run. step.do runs code, persists the return value, and on retry resumes from the last successful step rather than re-running completed work.

step.do(name, callback) - Executes code and persists the result. If the Workflow is interrupted or retried, it resumes from the last successful step rather than re-running completed work.

— Cloudflare, Build your first Workflow

When deciding step boundaries, ask whether you want all of the code to run again if one part fails. Separate steps suit external API calls, database queries, and storage reads so a later failure retries from that point using data already fetched.

Return values must be serializable. Non-stream results are capped at 1 MiB per step; for larger binary output in JavaScript Workflows you can return a fresh, unlocked ReadableStream<Uint8Array> (not BYOB streams or already-read streams). Very large artifacts should live in R2 (or similar) with a reference returned from the step—see Rules of Workflows.

step.sleep pauses for a relative duration (for example "20 seconds"). step.sleepUntil waits until a fixed time. step.sleep and step.sleepUntil do not count toward the per-instance step limit (Workers API, Limits).

Step context: retry attempt, name, and config inside step.do

Section titled “Step context: retry attempt, name, and config inside step.do”

Every step.do callback can receive WorkflowStepContext as its first argument: step.name, step.count (how many times that name was invoked in this instance, 1-indexed—useful in loops), attempt (1 on first try, 2 on first retry), and config (resolved retries and timeout).

The step.do() callback receives a context object with new properties alongside attempt: step.name, step.count, and config — The resolved step configuration, including timeout and retries with defaults applied.

— Cloudflare, Additional step context and ReadableStream support now available in Workflows step.do()

Use ctx.attempt for logging, fallback endpoints, or logic that changes on retries. Full detail is in Step context.

Sleeping and retrying: defaults, dynamic delays, NonRetryableError

Section titled “Sleeping and retrying: defaults, dynamic delays, NonRetryableError”

Per-step retry behavior is optional WorkflowStepConfig on step.do. If you omit it, Workflows applies defaults (5 retries, 10s delay, exponential backoff, 10-minute timeout per attempt)—see Sleeping and retrying.

You can set retries.limit (up to 10,000 per step), fixed or human-readable delay, backoff (constant | linear | exponential), and timeout per attempt. Dynamic delay functions receive { ctx, error } and return a duration string, number, or promise—handy for rate limits or Retry-After-style errors:

delay: ({ ctx, error }) => {
if (error.message.includes("rate limit")) {
return `${ctx.attempt * 30} seconds`;
}
return "10 seconds";
},

Throw NonRetryableError for permanent failures (for example failed moderation) so the instance fails without further step retries; registered rollback handlers still run when applicable (Sleeping and retrying).

step.waitForEvent: webhooks, approvals, and sending events

Section titled “step.waitForEvent: webhooks, approvals, and sending events”

step.waitForEvent blocks until an event with a matching type arrives or the step times out (default 24 hours, configurable from 1 second up to 365 days). Event type values support letters, digits, -, and _ (not .).

The new step.waitForEvent API allows a Workflow instance to wait on events and data, enabling human-in-the-the-loop interactions, such as approving or rejecting a request, directly handling webhooks from other systems, or pushing event data to a Workflow while it’s running.

— Cloudflare, Workflows is now Generally Available

Passing data in:

  1. env.MY_WORKFLOW.create({ params: { ... } }) when starting the instance (Events and parameters).
  2. instance.sendEvent({ type, payload }) while the instance is running—the type must match the waitForEvent option.

Events can be sent before the workflow reaches the matching waitForEvent; they are buffered until that step. WorkflowEvent.payload is immutable—mutations are not persisted; return durable state from step.do instead (Events and parameters).

On timeout, waitForEvent throws and the instance fails unless you catch and branch (for example default action without approval).

Saga rollback: compensating steps on failure

Section titled “Saga rollback: compensating steps on failure”

Workflows supports saga-style rollbacks: optional rollback handlers on step.do. If the instance fails, rollbacks run in reverse step-start order, each with its own rollbackConfig (retries, timeout). Rollback handlers receive ctx (original step context), output, and error.

Workflows now supports saga-style rollbacks, allowing you to add compensating logic to each step.do() in case of downstream failures. If the instance fails, the rollback handlers will execute in reverse step-start order.

— Cloudflare, Rollback support now available in Workflows

Instance status and analytics expose rollback lifecycle (ROLLBACK_START, ROLLBACK_COMPLETE, ROLLBACK_FAILED, and step-level rollback events) so you can tell forward failures from compensation failures (Metrics and analytics).

Rules of Workflows: common mistakes that break durability

Section titled “Rules of Workflows: common mistakes that break durability”

The Rules of Workflows guide is the reference for correct step design. In short:

Practice Why it matters
Keep steps granular and idempotent where APIs can double-apply Retries re-run the failing step
Persist state only via step.do return values, not in-memory variables The engine may hibernate and lose heap state
No side effects outside step.do you cannot tolerate repeating Engine restarts can re-execute non-step code
Do not mutate event.payload Changes are not persisted across steps
Deterministic step names Names act as cache keys for completed step output
Await every step.do / step.sleep Dangling promises swallow errors and state
Wrap Promise.race / Promise.any in a single outer step.do Avoid nested step.do inside races
Branch on event.payload or prior step outputs, not Math.random() outside a step Restarts must take the same path

For Hyperdrive, open a new connection inside each step, not shared across steps.

Trigger Workflows: create instances and child workflows

Section titled “Trigger Workflows: create instances and child workflows”

Trigger paths include Worker fetch handlers, queue or scheduled handlers, cron on the Workflow binding, REST API, and wrangler workflows trigger (Trigger Workflows).

A parent can start a child with this.env.CHILD_WORKFLOW.create({ id, params }) inside step.do; the parent does not wait for the child to finish—only for successful creation (Trigger Workflows).

Minimal pattern from the getting started guide:

const instance = await env.MY_WORKFLOW.create();
return Response.json({ instanceId: instance.id });
// Later: (await env.MY_WORKFLOW.get(instanceId)).status()

See Build with Workflows for instance events, testing, and Pages integration.

Limits, concurrency, subrequests, and billing

Section titled “Limits, concurrency, subrequests, and billing”

Authoritative numbers are in Limits. Highlights for Paid vs Free:

Dimension Workers Free Workers Paid
Steps per instance 1,024 10,000 default, up to 25,000 in Wrangler limits.steps
Persisted state per instance 100 MB 1 GB
Concurrent running instances 100 50,000 (changelog raises from 10,000)
Queued instances per Workflow 100,000 2,000,000
Instance creation rate 100/s 300/s per account, 100/s per workflow
Subrequests per Workflow instance 50 10,000 default, up to 10 million via limits.subrequests
Steps billing 3,000/day included 500,000/month included, then per-step charges

Instances that are in a waiting state — either sleeping via step.sleep, waiting for a retry, or waiting for an event via step.waitForEvent — do not count towards concurrency limits.

— Cloudflare, Limits

Long Workflows that issue many fetch() calls benefit from raised Worker subrequest limits (Workers are no longer limited to 1000 subrequests). Simultaneous connection counting for Workers now frees a slot when response headers arrive, which helps I/O-heavy steps (Relaxed simultaneous connection limiting for Workers).

Storage and retention: persisted instance state is billed in GB-months (Pricing). On Paid, new Workflows created on or after September 10, 2026 default to 7 days retention for completed/errored instances (max 30 days); override with successRetention / errorRetention on create (Default instance retention). Step and storage billing on Paid starts no earlier than August 10, 2026 (Workflows pricing adds per-step billing).

Configure higher step counts in Wrangler:

"workflows": [{ "name": "my-workflow", "binding": "MY_WORKFLOW", "class_name": "MyWorkflow", "limits": { "steps": 25000 } }]

Observability: dashboard diagrams and analytics event types

Section titled “Observability: dashboard diagrams and analytics event types”

The dashboard can render beta diagrams of JavaScript/TypeScript Workflow structure (steps, loops, branches)—see Visualize Workflows and Visualize your Workflows in the Cloudflare dashboard. Python Workflows are not supported for diagrams.

Metrics and analytics document workflow- and step-level eventType values, including rollback labels. You can query stepCount per instance via the GraphQL Analytics API (Workflows pricing adds per-step billing).

Diagnostics channels also emit workflow lifecycle events such as workflow:start and workflow:event (Diagnostics channels).

Python Workflows and DAG-style dependencies

Section titled “Python Workflows and DAG-style dependencies”

Python Workflows use @step.do() decorators; dependencies are inferred from parameter names, with concurrent=True for parallel dependency resolution (DAG Workflows, Python Workers API). Bindings support send_event from Python Workers (Interact with a Workflow).

  1. Deploy a Workflow class and binding per Build your first Workflow, then trigger an instance with env.MY_WORKFLOW.create({ params }) or Events and parameters CLI: npx wrangler@latest workflows trigger workflows-starter '{"some":"data"}'.

  2. Poll status with const instance = await env.MY_WORKFLOW.get(instanceId); await instance.status() as in the getting started Write your API section; confirm steps complete and outputs match expectations.

  3. If using waitForEvent, send a matching event with instance.sendEvent({ type, payload }) and verify the instance leaves the waiting state (Events and parameters).

  4. Open the Cloudflare dashboard Workflows view to inspect instance timelines, diagrams (JS/TS), and usage before step/storage billing changes (Workflows pricing adds per-step billing).

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.