A Workflow is a durable function that runs as a named sequence of steps,
sleeps, and events. On one machine, workerd keeps each Workflow instance in
one Durable Object, under .wrangler/state/workerd/workflows/. In a
cluster, workerd copies the Workflow instances to the bucket, so another
instance can serve them. Read the
Cloudflare Workflows documentation
for the API.
Example
The Workflow example fetches a document and stores the result of a durable step.
import { WorkflowEntrypoint } from "cloudflare:workers";
export class ReportBuilder extends WorkflowEntrypoint {
async run(event, step) {
// A completed step returns its stored result when the Workflow resumes.
return await step.do("build report", async () => {
const response = await fetch(event.payload.url);
if (!response.ok) throw new Error(`source answered ${response.status}`);
const text = await response.text();
return { bytes: text.length, lines: text.split("\n").length };
});
}
}
export default {
async fetch(request, env) {
const url = new URL(request.url);
const id = url.searchParams.get("id");
if (url.pathname === "/create") {
const instance = await env.REPORTS.create({
params: { url: url.searchParams.get("url") ?? "https://example.com" },
});
return new Response(instance.id);
}
if (url.pathname === "/status" && id) {
const instance = await env.REPORTS.get(id);
return Response.json(await instance.status());
}
return new Response("Use /create?url=URL or /status?id=ID.", {
status: 404,
});
},
};{
"name": "workflow",
"main": "index.js",
"compatibility_date": "2026-08-18",
"no_bundle": true,
"workflows": [
{
"binding": "REPORTS",
"name": "report-builder",
"class_name": "ReportBuilder"
}
]
}Workflows are experimental, so they need --experimental:
npx workerd serve --experimental ./workflow/wrangler.jsonc
ID=$(curl -s http://localhost:8787/create)
curl "http://localhost:8787/status?id=$ID"/create returns the new Workflow instance’s id. The status is running
until the step has run, then complete, with the step’s result as
output.
A Workflow instance’s run() stays in memory until it finishes. It
runs again from its first line after a crash or a restart. It also runs
again after a sleep or an event wait of more than 60 seconds, when no other
part of it runs. A completed step then returns its stored result and does
not run its callback. A wait keeps its deadline. Put each side effect
inside a step.do() callback, as the
rules of Workflows
require.
Differences from Cloudflare
- A
workflowsentry takesbinding,name,class_name,limits.steps, anddefault_retention. workerd ignoresconcurrencyandjurisdiction. It refusesschedules, and ascript_namethat names another Worker. - workerd keeps a finished Workflow instance for 30 days.
retentionordefault_retentioncan set another period.createBatch()with an array ignoresretention. - workerd ignores
locationHint. OnlycreateBatch()withinstanceschecks its value. - workerd has no Workflows REST API. Use the binding instead.
See also Cloudflare compatibility.