Queues
Add a message queue binding to your Ploy worker in ploy.yaml, send single, delayed, or batched messages, and process them in the background in a queue handler.
Queues
Ploy Queues let you send messages to be processed asynchronously by your worker. Messages are durably stored and delivered at least once.
Use a queue when a request should return before the work is done: sending email, processing uploads, syncing with third-party APIs, or fanning out notifications. If the work has several dependent steps that must survive failures, use a Workflow instead.
This page covers the binding and its runtime API. For framework-specific setup, see the Next.js queues guide and the Ploy Start queues guide.
Configuration
Add a queue binding in your ploy.yaml:
kind: worker
build: pnpm build
out: dist
queue:
TASKS: tasksThe key (TASKS) is the binding name available in your worker's env. The value (tasks) is the queue identifier.
Run ploy types to generate TypeScript types:
import type { QueueBinding } from "@meetploy/types";
export interface Env {
TASKS: QueueBinding;
}Basic Example
export default {
async fetch(request, env) {
// Send a message to the queue
const { messageId } = await env.TASKS.send({
task: "process-order",
orderId: "123",
});
return Response.json({ messageId });
},
// Handle incoming messages
async message(event) {
console.log("Processing:", event.payload);
},
} satisfies Ploy;Sending Messages
Single Message
const { messageId } = await env.TASKS.send({ task: "process" });Delayed Message
const { messageId } = await env.TASKS.send(
{ task: "reminder" },
{ delaySeconds: 60 },
);Batch Send
const { messageIds } = await env.TASKS.sendBatch([
{ payload: { task: "batch-1" } },
{ payload: { task: "batch-2" } },
{ payload: { task: "batch-3" } },
]);Message Handler
The message handler receives a QueueMessageEvent:
async message(event) {
console.log({
id: event.id,
queue: event.queueName,
payload: event.payload,
attempt: event.attempt,
});
}Messages that throw an error are automatically retried with exponential backoff.
Each message can spend 5 s (Free), 30 s (Pro), or 5 min (Enterprise) of CPU time, depending on your plan. See CPU limits.
Concurrency
A project processes up to 2 (Free), 10 (Pro), or 25 (Enterprise) messages at once, across all of its queues. When a backlog builds up, the rest of the messages wait in the queue and are delivered oldest first as earlier ones finish, so a burst of messages never delays your other projects or your app's requests.
Next Steps
- Next.js queues guide - Send and process messages from a Next.js app
- Ploy Start queues guide - Type-safe message handlers with Zod validation
- Workflows - Orchestrate multi-step processes
- Workers - Learn about Ploy workers
How is this guide?
Last updated on
Databases
Add a SQLite database binding to your Ploy worker in ploy.yaml, generate types with ploy types, and query it with prepare(), all(), first(), and run().
Workflows
Build durable multi-step workflows on Ploy: bind them in ploy.yaml, trigger and cancel executions, configure step retries, and use step.run and step.sleep.