Discover how the Vercel Workflow SDK and the use workflow directive bring durable background jobs to Next.js without the complexity of traditional queues.

Modern web applications are increasingly expected to perform complex, asynchronous tasks that outlive the immediate lifecycle of a single user request. Whether you are sending a sequence of onboarding emails, processing a heavy file upload, or coordinating multi-step reasoning loops for artificial intelligence agents, blocking the client while these operations run is not an option. You need to return a fast response to the browser and execute the heavy lifting in the background.
In serverless architectures, managing these background tasks has historically been a major pain point. Without dedicated infrastructure, developers have had to spin up external Redis databases, configure complex queue managers, and maintain a fleet of dedicated background workers. These setups introduce substantial hosting costs, configuration friction, and deployment complexity to what should be simple business logic.
To solve this, the engineering team at Vercel introduced a new programming model for serverless asynchronous execution. By combining the open source Workflow Development Kit with native platform primitives, developers can now write durable, resilient background processes directly within their existing application codebases. This approach eliminates the need for separate queue infrastructure, bringing resilience and observability directly to the application layer.
In this guide, we will explore how we utilize the Vercel Workflow SDK and its compiler directives to build crash-resistant, long-running processes. We will dissect the underlying architecture, walk through the setup process, and compare this modern model against traditional queueing systems to help you decide when to adopt it.
The Vercel Workflow SDK handles durable background jobs in Next.js by compiling functions marked with the use workflow directive into a deterministic state machine. Each step executes in an isolated environment, persisting its output to a managed event log, which allows the workflow to survive serverless timeouts, restarts, and redeployments by resuming exactly where it paused.
Instead of keeping a serverless function running indefinitely (which would trigger platform timeouts), the runtime executes step functions as independent, retriable HTTP endpoints. If an execution is interrupted, the SDK replays the orchestrator from the beginning, injecting cached results from the event log for already completed steps and executing only the remaining pending work.
The life of a standard serverless function is brief. On most modern cloud platforms, serverless executions are designed to be short lived, often timing out after 15 to 30 seconds. While this model is highly cost effective for serving standard web requests, it breaks down completely when your application needs to perform work that spans minutes, hours, or even weeks.
Suppose your application needs to onboard a new user. You want to send a welcome email immediately, wait seven days, and then send a targeted follow-up message. Attempting to handle this with a standard asynchronous function and a JavaScript timer fails because the serverless container is torn down almost immediately after the initial response is sent. The timer is lost, the execution context is destroyed, and your background job dies silently.
Even for shorter tasks, such as calling a third-party API to process a payment, serverless functions are highly vulnerable to network instability. If the downstream payment gateway experiences a brief outage, your serverless function will either block until it times out or fail outright, leaving your database in an inconsistent state. Surviving these transient failures requires building custom retry loops, implementing exponential backoff strategies, and writing complex error-handling code.
To guarantee that these tasks execute to completion, engineering teams have historically had to build and maintain extensive worker tiers. This typically involves provisioning a Redis cluster, configuring a queue library like BullMQ, writing worker processes that run continuously on virtual machines, and managing state synchronization between your primary web application and the worker fleet. For many teams, the operational overhead of managing this infrastructure quickly becomes more complex than writing the actual product features.
The Vercel Workflow SDK, which reached general availability in early 2026, represents a fundamental shift in how developers handle asynchronous execution. Instead of treating durability as an infrastructure problem that must be solved with external queues and databases, the SDK makes durability a language-level concept. You write ordinary TypeScript functions, and the platform handles the orchestration, persistence, and recovery automatically.
Vercel Workflows has already processed over 100 million runs and over 500 million steps across more than 1,500 customers.
This massive adoption is driven by the simplicity of the developer experience. By installing the open source workflow package, you gain access to a framework-agnostic runtime that runs anywhere. When deployed to Vercel, this runtime integrates with Fluid compute and Vercel Queues to provide a fully managed, zero-config backend that handles step queuing, end-to-end encryption, and real-time observability.
For engineering teams, this means you no longer need to provision separate databases or manage complex worker fleets. Your background jobs live alongside your UI components and API routes in a single, unified codebase. This unified approach dramatically simplifies local development, testing, and deployment, allowing teams to move faster while shipping highly resilient features.
The magic of the Workflow Development Kit lies in its build-time code transformations and its unique execution model. When you place the use workflow directive as a string literal at the top of an asynchronous function, you are signaling to the compiler that this function is an orchestrator. The SWC compiler plugin, integrated into your Next.js build process, takes this function and compiles it into a deterministic state machine.
This orchestrator function does not run in a standard Node.js environment. Instead, it executes in a highly restricted, sandboxed environment where it cannot perform direct side effects. It cannot read from the filesystem, write to a database, or make direct network requests. This restriction is a necessary architectural trade-off that enables the SDK's replay mechanics.
During a workflow's lifecycle, the orchestrator function is executed multiple times from the very first line. Every time the workflow needs to progress to a new step, the runtime re-runs the orchestrator. As it executes, the SDK intercepts each step call and checks the persistent event log. If a step has already executed successfully in a previous run, the SDK immediately injects the cached result and skips execution, moving directly to the next pending step.
This replay model ensures that the control flow (such as loops, conditionals, and branching logic) remains completely synchronized with the recorded history. Because the function is re-evaluated repeatedly, any non-deterministic behavior inside the orchestrator would break the state machine. If the control flow changed dynamically based on a random number or a real-time database query, the replay would diverge from the event log, causing the workflow to fail.
To perform the actual work of your application, you must isolate all side effects within independent, atomic units called steps. You define these steps by creating asynchronous functions marked with the use step directive. When the compiler encounters this directive, it transforms the function into an independent, retriable HTTP handler.
Unlike the orchestrator, step functions run in a full Node.js environment. Inside a step, you have complete access to the entire npm ecosystem, your database clients, and external network APIs. You can safely read and write data, initiate external webhooks, or perform heavy computations.
When the orchestrator encounters a step function during execution, it does not run the code inline. Instead, it schedules the step for execution via the managed queue backend. The backend invokes the step's specific HTTP endpoint, executes the code, and records the returned value in the persistent event log.
If a step function fails due to a network error or an API outage, the orchestrator does not crash. The backend automatically schedules a retry for that specific step, utilizing exponential backoff to avoid overwhelming the downstream service. Because completed steps are already recorded in the event log, those successful steps are never executed again. This atomic separation guarantees that your side effects (such as charging a customer's credit card or creating a user record) happen exactly once, even if the surrounding system experiences multiple failures.
Integrating the Workflow Development Kit into a modern Next.js project (such as a Next.js 16 build running with Turbopack) is a straightforward process. Because the SDK relies on build-time transformations, you must configure the Next.js bundler to recognize and compile the workflow directives.
Our web application design and development team recommends starting by installing the core package using your preferred package manager. You simply run the command npm install workflow in your project root. This installs the open source engine, local development tools, and TypeScript types.
Once the installation is complete, you must update your next.config.ts file. By importing the withWorkflow wrapper from workflow/next and wrapping your default Next.js configuration, you enable the SWC compiler plugin. This plugin automatically parses your codebase during compilation, searching for functions that contain the use workflow or use step directives.
With the configuration in place, you can organize your workflow files. A highly recommended pattern is to create a dedicated directory named workflows at the root of your project. Inside this directory, you can create subfolders for each unique background process, housing your orchestrator function and its associated step functions in clean, modular files.
To kick off a background job from a Next.js Route Handler or a Server Action, you import the start function from workflow/api. You pass your orchestrator function and its required arguments to this call. The API route executes almost instantly, returning an execution ID to the client, while the workflow engine schedules and runs the steps asynchronously in the background.
The defining characteristic of a durable execution framework is its ability to survive unexpected crashes, server restarts, and platform redeployments mid-execution. Understanding how the Vercel Workflow SDK achieves this resilience requires a closer look at the mechanics of determinism and the replay loop.
When a workflow is interrupted (for example, if the serverless container hosting your function experiences a cold start or is terminated during a deployment), the runtime does not lose your progress. Instead, the engine schedules a new execution of the orchestrator function. As the orchestrator runs again from the very first line, the SDK intercepts every call to a step function and checks the event log for that specific run ID.
If the event log shows that Step 1 has already completed and returned a value, the SDK immediately injects that stored value and moves to the next line of code. It does not invoke the actual code inside Step 1 again. This process continues until the orchestrator reaches a step that has not yet been recorded, at which point the engine executes that step and appends the result to the log.
Because the orchestrator is executed repeatedly from the beginning, your code must remain completely deterministic. If you generate a random number or read the current system time directly inside the orchestrator, that value will change on every replay, breaking the consistency of your control flow. To protect developers from these issues, the sandboxed environment mocks common non-deterministic APIs. For instance, Math.random() and the Date constructor are stubbed to return the exact same values across replays of a single workflow run, ensuring safe execution without requiring complex custom workarounds.
Beyond standard retries and crash survival, the Vercel Workflow SDK enables advanced execution patterns that were previously incredibly difficult to implement in serverless environments. Chief among these is the ability to pause execution for extended periods without consuming any compute resources.
By importing the sleep function directly from the workflow package, you can pause your background jobs for minutes, hours, or even up to 30 days. When the orchestrator encounters a call like await sleep("7 days"), the SDK suspends the workflow, records the target wake-up time in the managed database, and immediately terminates the active serverless function. No compute resources are held open, and you are not billed for idle time. When the seven days have elapsed, the Vercel scheduler automatically triggers a replay of the orchestrator, resuming execution exactly where it left off.
Another highly powerful pattern is human-in-the-loop execution. This allows a workflow to pause and wait for an external event, such as a manual approval from an administrator or a verification webhook, before proceeding to high-value actions.
A prime example of this pattern in practice is integrating with cryptographic proof of human protocols. By utilizing integrations like World ID's proofOfHuman API, developers can suspend a sensitive workflow step until a verified human action is received. The workflow remains suspended indefinitely in a cost-free state, waking up and resuming only when the secure webhook registers the user's verification.
When choosing a background execution model, it is helpful to contrast the Vercel Workflow SDK against traditional message queues and dedicated orchestration platforms. In our custom software development practice, we evaluate these options based on infrastructure overhead, developer experience, and execution characteristics.
Standard message queues (such as AWS SQS or RabbitMQ) require substantial manual provisioning and separate worker fleets, which introduces significant architectural complexity. Code-first orchestration engines (like Temporal or Inngest) offer incredible durability but often require you to run separate coordinator clusters or adapt to highly proprietary APIs. The Workflow Development Kit, by contrast, compiles directly into your primary application, offering a serverless-native experience with zero infrastructure management.
| Feature | Standard Message Queues (SQS, RabbitMQ) | Dedicated Orchestrators (Temporal, Inngest) | Vercel Workflow SDK |
|---|---|---|---|
| Infrastructure Setup | Manual database & worker provisioning | High (requires cluster management) | Zero (completely serverless-native) |
| Developer Experience | Low (requires custom polling/routing) | Medium (requires learning proprietary DSLs) | High (uses standard TypeScript functions) |
| Execution Model | Fire-and-forget message passing | Event-driven step runner | Deterministic replay state machine |
| Replay Mechanics | None (failed messages are retried from start) | Step-level caching and execution | Event log replay with automatic stubbing |
| Hosting Model | Self-hosted or managed cloud | Managed cloud or self-hosted cluster | Native to Vercel (or self-hosted World) |
For teams seeking maximum velocity without sacrificing reliability, the serverless-native model of the Vercel Workflow SDK is incredibly compelling. It provides the durability of a distributed state machine with the simplicity of writing a standard async/await function.
The rise of agentic artificial intelligence has made durable background execution more critical than ever. Unlike standard web applications that follow predictable, linear execution paths, AI agents run complex, multi-step reasoning loops that are highly non-deterministic and prone to failure.
Building reliable agents requires a system that can handle slow model evaluations, recover from API rate limits, and maintain state across multiple turns. In our post on custom agent workflows, we discussed how the true competitive advantage for modern AI applications lies in the orchestration layer rather than the underlying model. By utilizing the Vercel Workflow SDK, you can build self-healing agent loops that execute with complete resilience.
For example, you can design a workflow that generates code based on a user's natural language prompt, writes its own test suite, and executes those tests inside an isolated microVM using Vercel Sandbox. If the tests fail, the workflow can capture the error logs, loop back to the generation step, and ask the LLM to fix the bug.
Because each step is wrapped in a use step directive, every LLM call, code compilation, and test execution is persisted in the event log. If the process is interrupted, the agent resumes from the exact step it was executing, avoiding the massive latency and cost of re-running the entire reasoning chain from scratch.
We highlighted this exact architectural approach in our guide to collaborative agentic workflows, where maintaining consistent execution state across multiple collaborative agents is paramount to preventing system drift.
While the Vercel Workflow SDK offers a remarkably elegant developer experience, it is not a universal solution for every asynchronous task. Making an informed architectural decision requires a candid look at the associated costs, potential pitfalls, and scenarios where this tool is not the right fit.
First, let's look at the financial aspect. While local development and testing are completely free, running workloads in production on Vercel's managed platform utilizes Fluid Compute and Vercel Queues. Under this billing model, each step execution and subsequent orchestrator replay registers as a serverless invocation. If you have high-volume, low-latency tasks (such as processing tens of thousands of real-time IoT telemetry events per second), the sheer volume of database writes to the event log and serverless invocations will quickly lead to substantial hosting costs.
Second, you should skip this tool if your background tasks require sub-millisecond execution times. The coordination overhead introduced by the state machine, network-hop persistence, and step queuing means that Vercel Workflows is designed for durability, not raw speed. For high-frequency, low-latency data ingestion, standard message brokers or stream processors remain the superior choice.
A common pitfall that teams encounter early on is accidentally importing Node.js native modules (such as crypto or fs) directly into the workflow orchestrator file. Because the orchestrator function must remain sandboxed to guarantee determinism, the compiler will throw a build error if it detects native imports.
You must strictly isolate all side-effect-heavy imports within separate step files. This separation of concerns requires a deliberate design approach, but it is exactly what ensures your workflows remain robust and maintainable over their entire lifecycle.
Key takeaways
- Durability Made Simple: The Vercel Workflow SDK brings robust background jobs directly into Next.js using native TypeScript directives, eliminating the need to manage external queues.
- Replay Mechanics: By persisting progress to an event log, workflows survive serverless timeouts and redeployments, resuming execution exactly where they paused.
- Separation of Concerns: Orchestrators must remain completely deterministic, while any side effects or network calls must be isolated within retriable step functions.
- Advanced Capabilities: Built-in support for long-duration sleeps and human-in-the-loop pauses opens up powerful patterns for user onboarding and AI agents.
The use workflow directive defines the orchestrator function, which manages the overall control flow and must remain completely deterministic and sandboxed. The use step directive defines atomic execution units that perform the actual work (such as database writes or API calls) and run in a full Node.js environment with retry capabilities.
Yes, the core SDK is framework-agnostic and open source. While Vercel provides a fully managed hosting environment with zero-config databases and queues, you can self-host workflows by configuring a custom "World" backed by a PostgreSQL database or a Redis instance.
The SDK prevents duplicate executions by recording the output of every step in a persistent event log. When a workflow replays after an interruption, the engine checks this log and injects the cached result for any completed steps rather than running the code inside the step again.
Individual step functions are executed as serverless functions, meaning they are subject to the standard execution limits and timeouts of your hosting platform (such as 15 seconds on Vercel Hobby plans or longer on Pro and Enterprise). However, the overall workflow can span up to 30 days by using the built-in sleep function.
The Workflow SDK includes a local development engine that runs alongside your Next.js development server. You can inspect, trigger, and debug your active runs using the local web interface by running the command npx workflow web in a separate terminal window.
To protect developers, the SDK's sandboxed environment stubs common non-deterministic JavaScript features like Math.random() and new Date(). These stubs return the exact same values across replays of the same run, ensuring that your orchestrator's control flow remains perfectly consistent.
No, it is not suitable for high-frequency pipelines. The overhead of step serialization, network persistence, and queuing coordination is designed for durability rather than sub-millisecond latency. For high-throughput ingestion, you should use dedicated streaming platforms like Apache Kafka.
When you deploy a new version of your application, active workflows remain pinned to the deployment that started them to prevent version mismatch errors. If a workflow spans several days, it will continue executing against the original code version until it completes, ensuring execution safety.
The Vercel Workflow SDK and its compile-time directives represent a massive leap forward in how we build, deploy, and maintain asynchronous systems. By elevating durability to a language primitive, developers can bypass the complex infrastructure of traditional queues and write resilient background jobs using standard TypeScript control flow. This serverless-native model drastically reduces operational overhead, allowing engineering teams to focus on shipping high-value features.
From coordinating multi-step user onboarding flows to building self-healing AI agent loops, the ability to write reliable, long-running background processes directly within Next.js changes the game for modern web development. While the financial and latency trade-offs must be evaluated for high-volume use cases, the developer experience and system resilience make this a highly compelling addition to the Next.js ecosystem.
If you are planning a complex web application build or looking to migrate legacy background workers to a more maintainable, modern stack, our team of engineers is here to help. We invite you to explore our custom software development services to learn how we can partner to build fast, reliable, and scalable digital products for your business.
01 · RelatedCollaborative agentic workflows are here. Learn how to implement Vercel for Slack and the Cline AI SDK adapter to build secure, transparent, multi-agent systems.
Read post
02 · RelatedNext.js 16.3 introduces instant navigations and AI agent optimization tools. Learn how to configure reusable static shells, write Playwright regression tests, and use AGENTS.md to guide AI coding tools.
Read post
03 · RelatedVercel's transition to a monthly scheduled security release program and 9 active CVEs make upgrading legacy Next.js 13.x and 14.x builds a business-critical priority.
Read postWe will reply in plain English within one business day, NDA on request. Discovery call is free.
We design and engineer software, mobile, and web products end-to-end. Send the brief, we will reply within one business day.
Start a projectWe send a short email whenever we publish a new field note or ship a studio update. No fixed schedule, no filler.
Unsubscribe in one click. We never share your address.