Run Workflows inside Dynamic Workers with @cloudflare/dynamic-workflows
Key Points
- Durable Workflows in Dynamic Workers
- Worker Loader reloads matching worker on wake
- wrapWorkflowBinding tags instances with tenant metadata
Summary
The @cloudflare/dynamic-workflows library lets you run Workflows inside Dynamic Workers and preserve durable execution even when Dynamic Worker code is loaded on demand and evicted from memory. Each Workflow instance is tagged with metadata (for example, tenantId) so the Worker Loader can reload the correct Dynamic Worker when the Workflow wakes after long sleeps or restarts. The Workflows engine continues to handle persistence, retries, and normal Workflow semantics; you only need to load tenant code on demand and wrap the Workflows binding with identifying metadata.
Key Points
- Durable Workflows inside Dynamic Workers: Workflow instances include metadata used to reload the matching Dynamic Worker via the Worker Loader when a Workflow resumes.
- No upfront registration: Dynamic Workers and Workflow code can be loaded on demand (per-tenant or per-agent) — you don’t need to register every Workflow ahead of time.
- Integration pattern (TypeScript): use LOADER.get(tenantId, ...) to create the Dynamic Worker with env.WORKFLOWS set to wrapWorkflowBinding({ tenantId }).
- Entrypoint requirements: the createDynamicWorkflowEntrypoint entrypoint name must match
class_namein your Wrangler workflows binding. - Failover & retries: the Workflows engine continues to persist state and retry steps; your Workflow code is unchanged by the routing layer.
- Common use cases: per-tenant automations (SaaS), AI agent multi-step plans, multi-tenant job processing with per-customer logic.
Quick Integration Notes
- Use createDynamicWorkflowEntrypoint to return a WorkflowRunner that loads the tenant-specific entrypoint via the loader stub.
- Wrap the binding with wrapWorkflowBinding({ tenantId }) so every create() call is tagged and can be routed back to the tenant Dynamic Worker.
- Typical fetch handler: read x-tenant-id, call loadTenant(env, tenantId).getEntrypoint().fetch(request).
For a full walkthrough, follow the Dynamic Workflows guide linked in the release post.