Queues
One Worker drops messages into a queue and replies instantly; another Worker picks them up later, in batches, with automatic retries — no message gets lost.
What are Queues?
Cloudflare Queues is a message queue: a reliable waiting line where one Worker drops off messages and another Worker picks them up to process later. It guarantees delivery, so nothing is lost even if the receiver is busy or briefly fails.
A "message" is just a small chunk of data — for example "send a welcome email to user 123" or "resize this uploaded photo." Instead of doing that slow work while the user waits, you put a message in the queue and respond immediately. The work happens in the background.
Think of it like…
A queue is like a restaurant's order rail. The waiter (one Worker) clips order tickets on the rail and goes back to serving customers. The kitchen (another Worker) grabs tickets when ready and cooks them in batches. Nobody waits at the counter for their food to be made.
Why use it?
If your Worker tries to do everything during a single request, slow tasks make users wait and a single failure loses the work. A queue decouples "accepting the work" from "doing the work," making your app faster and far more reliable.
Respond instantly
Acknowledge the request in milliseconds, then do the heavy lifting in the background.
Guaranteed delivery
Messages are stored until successfully processed — they survive crashes and restarts.
Automatic retries
If processing fails, the message is retried automatically. No custom retry code needed.
Batching
Process up to 100 messages at once for big efficiency gains on bulk work.
No egress fees
You're never charged for bandwidth moving messages out of the queue.
Smooths spikes
A sudden flood of work piles up safely in the queue instead of overwhelming your system.
When should you use it?
Use Queues whenever work can happen later instead of right now, or when one part of your system needs to hand a job to another safely.
Sending emails
Queue a welcome or receipt email so the user's request returns instantly.
Media processing
Resize images or transcode video in the background after an upload.
Webhooks
Accept incoming webhooks fast, then process them reliably with retries.
Worker-to-Worker
Pass jobs between Workers without them having to call each other directly.
Batch ingestion
Buffer events and write them to storage in efficient batches.
Notifications
Fan out push or in-app notifications without blocking the original request.
How do you get started?
You create a queue with Wrangler, then wire one Worker as the producer (sends messages) and another handler as the consumer (processes them). A single Worker can be both.
Create a queue
Make a new queue by name. This is where messages will wait.
npx wrangler queues create my-queueAdd bindings in config
In wrangler.jsonc, declare the queue as a producer (so the Worker can send to it) and as a consumer (so the Worker is invoked to process batches).
{ "queues": { "producers": [ { "queue": "my-queue", "binding": "MY_QUEUE" } ], "consumers": [ { "queue": "my-queue", "max_batch_size": 10, "max_batch_timeout": 5 } ] } }Deploy
Publish your Worker. Use wrangler tail to watch messages being consumed live.
npx wrangler deploy npx wrangler tail
export default {
// PRODUCER: runs on each HTTP request and sends a message
async fetch(request, env, ctx) {
await env.MY_QUEUE.send({
url: request.url,
time: Date.now(),
});
return new Response("Queued!");
},
// CONSUMER: runs in the background with a batch of messages
async queue(batch, env, ctx) {
for (const message of batch.messages) {
console.log("Processing:", message.body);
// ...do the slow work here...
message.ack(); // mark this message as done
}
},
};ack and retry
Call message.ack() when a message is handled successfully. If your consumer throws an error or calls message.retry(), Queues will redeliver that message later — up to the retry limit — so failures heal themselves.
Key concepts
Producer
The Worker that sends messages into the queue with env.QUEUE.send().
Consumer
The queue() handler that Cloudflare invokes with batches of messages to process.
Batch
A group of up to 100 messages delivered together for efficient processing.
Acknowledge (ack)
Marking a message as successfully done so it won't be delivered again.
Retry
Redelivery of a message that failed, automatically, up to 100 attempts.
Dead Letter Queue
A separate queue where messages go after exhausting all retries, so you can inspect them.
Tips & pricing
Always set a Dead Letter Queue
Configure a dead letter queue so messages that keep failing don't vanish — they land somewhere you can inspect and fix later, instead of being dropped after the retry limit.
Good limits to remember
- Up to 10,000 queues per account
- Max message size: 128 KB
- Max batch: 100 messages (or 256 KB total)
- Max batch wait: 60 seconds
- Throughput: up to 5,000 messages/second per queue
- Retries: up to 100; retention configurable up to 14 days
Free to start, no egress
Queues is available on both Free and Paid plans, and never charges egress (bandwidth) fees. On the Free plan, message retention is fixed at 24 hours.
Related products
menu_bookOfficial docsopen_in_new