Queues Lab
Publish to a durable Vercel Queues topic and process messages with a private push consumer.
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/queues-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 Queues Lab demonstrates Vercel Queues (public beta): durable topics, fan-out consumer groups, and at-least-once delivery with retries. Producers call send() from @vercel/queue. A private consumer uses handleCallback and is registered with experimentalTriggers type queue/v2beta in vercel.json.
Features
- Live publish.
POST /api/queues/publishwithmode: "live"callssend('experiments-orders', payload). - Private fulfill consumer.
app/api/queues/fulfill/route.tsrecords processed messages when Queues invokes it. - Simulator mode. In-memory fan-out across
fulfillmentandanalyticsgroups, plus idempotency-key dedupe, for local learning without OIDC. - Honest errors. Missing OIDC returns
503with setup requirements instead of inventing message ids.
API Reference
POST /api/queues/publish
Prop
Type
GET /api/queues/publish
Returns the topic name, recent processed entries, and simulator backlog.
Consumer (POST fulfill)
Configured only via Queues push - not a public webhook:
{
"functions": {
"app/api/queues/fulfill/route.ts": {
"experimentalTriggers": [
{ "type": "queue/v2beta", "topic": "experiments-orders" }
]
}
}
}Implementation Details
Producer (live path):
const { send } = await import('@vercel/queue');
const result = await send(QUEUE_TOPIC, payload, idempotencyKey
? { idempotencyKey }
: undefined);Consumer:
export const POST = handleCallback(async (order, metadata) => {
recordProcessed({
messageId: metadata.messageId,
orderId: order.orderId ?? 'unknown',
receivedAt: new Date().toISOString(),
source: 'queue-callback',
});
});TopicSimulator in logic.ts models fan-out and retry/expire behaviour for the educational path.
Use Cases
- Offload email, PDF, or provider calls after a fast HTTP response
- Absorb traffic spikes with buffered processing
- Fan out one event stream to independent pipelines (analytics vs fulfillment)
Limitations
- Queues is in public beta; APIs and limits can change.
- Live mode needs OIDC (
vercel link+vercel env pull) or a Vercel deployment. - The in-memory log resets on cold start - it is not durable storage.
- Prefer Workflows when you need multi-step durable orchestration with sleep/hooks.
Use in your project
pnpm add @vercel/queue- Publish with
send(topic, payload) - Add a
handleCallbackroute andexperimentalTriggersinvercel.json - Keep handlers idempotent
Deployment
After deploy, publish with the UI (live mode) or curl, then check Observability - Queues and the recent-processed list in the demo.
Local Development
cd apps/experiments/queues-lab
pnpm install
vercel link && vercel env pull
pnpm devUse simulator mode without OIDC. Unit tests:
pnpm vitest run ../experiments/queues-labConfiguration
| Setup | Required | Notes |
|---|---|---|
OIDC via vercel env pull | Live publish/consume | Automatic on Vercel |
vercel.json queue trigger | Consumer | Already included |
Vercel / Next.js Features Used
- Vercel Queues
@vercel/queueSDK (send,handleCallback)- Next.js Route Handlers
- Function
experimentalTriggers