Update:Our Privacy Policy has changed

Durable workflows for serverless functions

Upstash Workflow turns an API route into a durable, multi-step process. Each completed step's result is saved, and failures retry only the step that failed. Sleep for days, wait for events, and call slow APIs without hitting function timeouts.

Why Upstash Workflow

Durable execution that runs inside the app you already deploy.

Durable steps

Each step's result is saved once it completes. If a step fails or the function crashes, the run resumes from the last finished step.

No function timeouts

Every step runs in its own invocation, so a workflow can run for hours or days on platforms with short time limits.

Sleep for days

Pause a run for minutes or days with context.sleep, up to a year on pay as you go. Nothing runs while it waits, and the whole sleep counts as one step.

Wait for events

Stop at a step until a user approves, a webhook arrives, or another service sends a notify, then continue.

Per-step retries

Failed steps retry on their own. Runs that still fail go to a dead letter queue where you can restart or resume them.

Parallel steps

Run steps side by side with Promise.all and wait for them together, each one durable and retried.

Flow control

Limit how many steps run at once and how fast, to protect databases and third-party API quotas.

Just your code

Workflows are plain TypeScript or Python in your existing API routes. No separate worker or orchestration server to deploy.

Write workflows as code

Wrap your logic in steps with the @upstash/workflow SDK and serve it from any API route.

// Step 1: Get the dataset URL
const datasetUrl = await context.run("get-dataset-url", async () => {
  return await getDatasetUrl(datasetId)
});

// Step 2: Download the dataset
const { body: dataset } = await context.call("download-dataset", {
  url: datasetUrl,
  method: "GET"
});

// Step 3: Analyze the dataset with LLM
const response = await context.api.openai.call(
  "call-openai",
  {
    token: "OPENAI_API_KEY",
    operation: "chat.completions.create",
    body: {
      model: "gpt-5.4",
      messages: [
        { role: "user", content: `Analyze this data chunk: ${JSON.stringify(dataset)}` },
      ],
    },
  }
);

What is durable execution?

Code that finishes what it started, even when the machine running it does not.

Durable execution means a function's progress is saved as it runs. The work is split into steps, and each step's result is recorded once it completes. If the process crashes or times out halfway through, it resumes from the last completed step instead of starting over or leaving work half done.

Serverless functions are the opposite by default. They have short time limits, keep no state between invocations, and a failure in the middle of a multi-step job usually means retrying everything or cleaning up by hand. Teams end up building their own queues, state tables, and retry logic around them.

Upstash Workflow provides that layer on top of QStash. Your workflow is an ordinary endpoint in your app. Workflow calls it once per step, passes in the results of earlier steps, and retries any step that fails. Sleeps and waits use no compute while they last, because nothing is running.

Frequently asked questions

Upstash Workflow is a durable execution platform for serverless apps. You write a workflow as an endpoint in your own app with the @upstash/workflow SDK, split into steps. Workflow runs each step, saves its result, and retries it on failure, so long and multi-step processes complete reliably on platforms with short function timeouts.

Durable execution records a function's progress step by step. If the process crashes or times out, it resumes from the last completed step instead of starting over. It replaces the hand-built queues, state tables, and retry logic that multi-step background jobs usually need.

Each step runs in its own invocation of your endpoint, so no single invocation has to run for the whole workflow. Waits like context.sleep and context.waitForEvent do not keep anything running. Long HTTP calls made with context.call are performed by Upstash, so your function does not wait for the response.

Workflow has TypeScript and Python SDKs. There are quickstarts for Next.js, Cloudflare Workers, Nuxt, SvelteKit, SolidJS, Hono, Express, Astro, TanStack Start, FastAPI, and Flask, and any platform that can serve an HTTP endpoint works.

A single sleep can last up to 7 days on the free plan and up to a year on pay as you go. Fixed plans have no maximum. Because a workflow is made of separate steps, the run as a whole is not bound by your platform's function timeout.

The step is retried automatically. Earlier steps are not run again, because their results are already saved. If the step still fails after its retries, the run moves to the dead letter queue, where you can restart it from the beginning or resume it from the failed step. You can also run a failure function to clean up or alert.

A step is one unit of work in your workflow, such as context.run, context.sleep, or context.waitForEvent. Each executed step is one billed step, and a retry is another step. context.call and context.invoke count as two steps, and each step that runs in parallel adds one extra step. See the pricing page FAQ for the full rules.

The free plan includes 1,000 steps a day. Pay as you go is $1 per 100K steps, with 50 GB of bandwidth free each month and $0.05 per GB after that. Fixed plans start at $180 a month for 1M steps a day. See the pricing page for details.

QStash is the message queue underneath Workflow. It delivers individual messages and runs schedules. Workflow adds steps, saved state, sleeps, and event waits on top, so a job with several dependent parts can be written as one function. Use QStash for single background jobs and Workflow for multi-step processes.

Ship your first workflow today

Start on the free tier with 1,000 steps a day. No credit card required.