Workflows Lab
Start a durable multi-step order workflow with use workflow, use step, and sleep on the Workflow SDK.
Run this experiment yourself
Demos are not embedded on this site. Deploy a standalone copy on Vercel or run the experiment app locally.
Local development
cd apps/experiments/workflows-lab pnpm install pnpm dev
Then open http://localhost:3010.
This is an experimental demo. Use it as a starting point for your own projects.
The Workflows Lab shows how Vercel Workflows turn ordinary async functions into durable runs. It uses the open-source Workflow SDK (workflow package): 'use workflow' for the orchestrator, 'use step' for retried side effects, and sleep() for pauses that consume no compute. A Route Handler calls start() from workflow/api so the HTTP response can return while the run continues.
Features
- Real Workflow SDK wiring.
next.config.mjswraps the Next config withwithWorkflow(). - Demo order workflow.
processDemoOrderreserves inventory, charges payment, sleeps 2 seconds, then sends confirmation. - Start API.
POST /api/workflows/startqueues a run and returnsrunIdwhen the platform is available. - Honest degradation. Without a linked Vercel project the route returns
503with setup requirements - it does not fake a run id. - Educational timeline. The UI also shows a client-side step timeline so you can learn the mental model offline.
API Reference
POST /api/workflows/start
Starts processDemoOrder with an order id.
Prop
Type
curl -X POST http://localhost:3010/api/workflows/start \
-H 'content-type: application/json' \
-d '{"orderId":"order_demo"}'Implementation Details
The workflow lives in apps/experiments/workflows-lab/workflows/demo-order.ts:
export async function processDemoOrder(orderId: string) {
'use workflow';
await reserveInventory(orderId, steps);
await chargePayment(orderId, steps);
await sleep('2s');
await sendConfirmation(orderId, steps);
return { orderId, status: 'confirmed', steps };
}Each helper is a 'use step' function. Steps get automatic retries for thrown errors; the workflow function coordinates them and may pause with sleep without holding a warm function.
withWorkflow from workflow/next generates the internal /.well-known/workflow/ routes the runtime needs.
Use Cases
- Multi-step onboarding or order pipelines that must survive deploys
- Agent tool loops that pause for human approval or external webhooks
- Delayed follow-ups (hours/days) without cron polling every minute
Limitations
- Live runs need Vercel (or
vercel devwith linked OIDC). Plainnext devwithout credentials returns503. - The on-page timeline is educational only - authoritative history is in Observability - Workflows /
npx workflow web. - Sleep in the demo is
2sso you can watch it finish; production sleeps can be much longer.
Use in your project
pnpm add workflow- Wrap
next.configwithwithWorkflow() - Export a
'use workflow'function and callstart(fn, [args])from a Route Handler
Deployment
Deploy the standalone app, trigger /api/workflows/start, then open Observability - Workflows in the project dashboard.
Local Development
cd apps/experiments/workflows-lab
pnpm install
vercel link && vercel env pull # OIDC for live start()
pnpm devOpen http://localhost:3010. Unit tests:
pnpm vitest run ../experiments/workflows-labConfiguration
| Variable / setup | Required | Notes |
|---|---|---|
Vercel OIDC (vercel env pull) | For live start() | Automatic on Vercel deployments |
withWorkflow(nextConfig) | Yes | Already set in this experiment |
Vercel / Next.js Features Used
- Vercel Workflows
- Workflow SDK (
'use workflow','use step',sleep,start) - Vercel Queues (underlying durable dispatch)
- Next.js Route Handlers