How Workflow works
We created Upstash Workflow to help you ship reliable code with minimal changes to your existing infrastructure:
- No more serverless function timeouts
- Automatic recovery when a workflow fails mid-execution
- Automatic retries when your service is temporarily unavailable
- Easily monitor system activity in real-time
Upstash Workflow is built on top of QStash, our serverless messaging and scheduling solution, to achieve these features. Here’s a simplified breakdown of how it works:
-
Call your workflow endpoint to trigger the workflow
-
The Workflow SDK sends a request to QStash with an automatically generated workflow run ID, headers, and the initial data as the request body
-
QStash calls your workflow endpoint with the current step to execute and the results of the previous steps:
- Skip successfully executed steps
- Assign previous step results to their respective variables
- Invoke the next step
In serverless environments, an API route is normally limited by a maximum function execution time (i.e. 10 seconds). By using context.run
, each step can now take up to the maximum duration, as each step is a separate HTTP request containing data from previous steps.
As Upstash Workflow is built on top of QStash, the context
methods map to QStash features:
context.run
-> regular QStash callcontext.sleep
andcontext.sleepUntil
-> QStash’s delay featurecontext.call
-> QStash’s callback feature
Retries, for example, are built into all QStash calls by default and, therefore, apply to every step in your workflow. For step-by-step resumability, QStash keeps a copy of your workflow state until the run is complete.
This architecture makes your serverless functions durable, reliable, and optimized for performance, even during runtime errors or temporarily unavailable services.