Skip to content
Back to Cloud Services

Cloudflare Queues Message Buffering

Durable message queues for Workers with batching, retries, and dead-letter queues for async processing.

CloudflareIntermediate

Why

Queues decouple producers from consumers, handle traffic spikes by buffering, and guarantee at-least-once delivery with automatic retries. Free tier: 1M operations/month, no idle cost.

Cloudflare's network spans 330+ cities in 125+ countries, serving 20% of all internet traffic. Workers have 0ms cold starts (isolate-based) and the free tier covers 100k requests/day.

When

Use Queues for email sending, webhook fan-out, image processing, and rate-limit smoothing. Avoid for strict ordering across partitions or needing exactly-once semantics.

How

1. Create queue — wrangler queues create my-queue 2. Producer — [[queues.producers]] binding="MYQ" queue="my-queue" 3. Consumer — [[queues.consumers]] queue="my-queue" max_batch_size=10 max_retries=3 4. Send — await env.MYQ.send({ body: JSON.stringify(payload) }) 5. Batch send — env.MYQ.sendBatch([{body:"a"},{body:"b"}]) 6. Consume — export default { async queue(batch, env) { for (const msg of batch.messages) {...} } } 7. Dead letter — dead_letter_queue="dlq" on consumer, failed messages go to DLQ

Example

// wrangler.toml [[queues.producers]] binding = "EMAILQ" queue = "email-queue" [[queues.consumers]] queue = "email-queue" max_batch_size = 10 max_retries = 3 dead_letter_queue = "email-dlq" // Producer (HTTP handler enqueues) export default { async fetch(request: Request, env: Env) { const { to, subject } = await request.json(); await env.EMAILQ.send({ body: JSON.stringify({ to, subject }) }); return Response.json({ queued: true }); }, // Consumer (batch process) async queue(batch: MessageBatch, env: Env) { for (const msg of batch.messages) { try { const { to, subject } = JSON.parse(msg.body); await sendEmail(env, to, subject); msg.ack(); } catch (e) { msg.retry(); // retried up to max_retries, then DLQ } } }, };

Common Problems

  • ⚠At-least-once not exactly-once — consumers must be idempotent, dedupe by message ID
  • ⚠max_batch_timeout too short — batch waits for size OR timeout, tune for latency vs throughput
  • ⚠Poison messages loop — without DLQ, retries exhaust and message blocks the queue

Best Practices

  • ✓Always set a dead-letter queue — prevents poison messages from blocking consumers
  • ✓Make consumers idempotent — use message ID + KV to dedupe, handles redelivery safely
  • ✓Batch aggressively — max_batch_size=100 cuts per-message overhead 10x

FAQ

What is Cloudflare Queues Message Buffering and what problem does it solve?

Durable message queues for Workers with batching, retries, and dead-letter queues for async processing. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with Cloudflare Queues Message Buffering in 5 minutes?

Two steps to run it: (1) Create queue — wrangler queues create my-queue; (2) Producer — [[queues.producers]] binding="MYQ" queue="my-queue". Validate on the free tier first, then wire into production.

What is the #1 pitfall with Cloudflare Queues Message Buffering?

The most frequent issue is: At-least-once not exactly-once — consumers must be idempotent, dedupe by message ID. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for Cloudflare Queues Message Buffering?

Best practices for Cloudflare Queues Message Buffering include: Always set a dead-letter queue — prevents poison messages from blocking consumers; Make consumers idempotent — use message ID + KV to dedupe, handles redelivery safely; Batch aggressively — max_batch_size=100 cuts per-message overhead 10x. The first one — "Always set a dead-letter queue — prevents poison messages from blocking consumers" — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with Cloudflare Queues Message Buffering?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most Cloudflare Queues Message Buffering options offer a free tier — validate within free quota before scaling.