Cloudflare Workflows Adds Saga Rollbacks for Durable Workflows
Add rollback functions to step.do() to automatically undo failed steps.
Implement rollback logic in your workflows.
Summary
Cloudflare Workflows now ships saga rollbacks, letting developers declare rollback logic within each step to automatically undo work when a later step fails. The new API allows a rollback function to be passed as the last argument to step.do(), and the framework will execute rollback handlers in reverse step‑start order when the workflow terminates.
Rollback handlers receive the step output and must be idempotent, using idempotency keys to safely retry without duplicating external actions. The saga pattern is illustrated with a fund transfer example where a debit step is undone by a credit step if the subsequent credit fails, ensuring consistency across external systems.
The implementation requires that any started or completed step with a rollback handler is eligible, and that rollback starts only when the workflow itself fails, not on individual step errors. Parallel steps use reverse step‑start order rather than completion order to determine rollback sequence, providing predictable behavior regardless of execution timing.
The API design evolved from a fluent approach to a rollback options object to preserve promise pipelining semantics in Workers. Developers can now write concise, maintainable workflows without manual try‑catch blocks, improving durability and developer experience.
Key changes
- Rollback logic can be defined per step via a rollback option in step.do().
- Rollbacks execute in reverse step‑start order when the workflow fails.
- Rollback handlers receive step output and must be idempotent, using idempotency keys.
- The saga pattern ensures compensation actions reverse external changes when a later step fails.
- Parallel steps use reverse step‑start order for rollback sequencing.
- Rollback starts only when the workflow itself fails, not on individual step errors.
- The API moved from a fluent chain to a rollback options object to maintain promise pipelining.
- Developers can now avoid manual try‑catch logic for compensation.