Execute long-running code flows durably with built-in retries, delays, and state persistence across function interruptions.
npm install @convex-dev/workflowHave you ever wanted to run a series of functions reliably and durably, where each can have its own retry behavior, the overall workflow will survive server restarts, and you can have long-running workflows spanning months that can be canceled? Do you want to observe the status of a workflow reactively, as well as the results written from each step?
And do you want to do this with code, instead of a static configuration?
Welcome to the world of Convex workflows.
Run workflows asynchronously, and observe their status reactively via subscriptions, from one or many users simultaneously, even on page refreshes.
Workflows can run for months, and survive server restarts. You can specify delays or custom times to run each step.
Run steps in parallel, or in sequence.
Output from previous steps is available to pass to subsequent steps.
Run queries, mutations, and actions.
Specify retry behavior on a per-step basis, along with a default policy.
Specify how many workflow steps can run in parallel to manage load.
Cancel long-running workflows.
Clean up workflows after they're done.
The Workflow component enables you to break long-running processes into durable steps that persist across function timeouts. Each workflow step executes with automatic retries and state preservation, allowing complex operations to complete reliably even if individual function calls fail or timeout.
Workflow provides built-in retry mechanisms with configurable delays between attempts. You can define custom backoff strategies and specify which errors should trigger retries, eliminating the need to implement retry logic manually in your Convex functions.
Workflows execute durably by persisting their state to the Convex database between steps. If a function is interrupted or fails, the workflow resumes from the last completed step rather than restarting from the beginning, ensuring reliable execution of multi-step processes.
The Workflow component automatically manages intermediate state for multi-step processes. You define workflow steps as regular functions, and the component handles state persistence, progress tracking, and coordination between steps without requiring manual state management code.
The Workflow component automatically persists workflow state to the database before each step executes. When a function times out, the workflow can resume from the last completed step rather than restarting entirely, ensuring progress is never lost during long-running operations.
Yes, Workflow allows you to configure retry strategies including which error types should trigger retries, maximum retry attempts, and delay patterns between retries. You can define different retry policies for different workflow steps based on your specific error handling needs.
Workflow state is persisted to the Convex database after each step completes successfully. If a function crashes or is interrupted, the workflow will resume from the last successfully completed step when it runs again, preserving all intermediate results and progress.
The Workflow component automatically manages data flow between steps through its state persistence mechanism. Return values from completed steps are stored and made available to subsequent steps, eliminating the need to manually manage intermediate data storage or retrieval.
Yes, workflow steps can call other Convex functions including mutations, queries, and actions. The Workflow component ensures these calls are made durably, with proper error handling and retry logic applied to maintain consistency across your application's data operations.