Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

Queue Batching, Retries, Acknowledgement and Delays

How managed queue consumers batch messages, acknowledge delivery, retry failures, and delay processing—with limits and verification.

This page summarizes Cloudflare’s documentation on Cloudflare Queues: a managed message queue for Cloudflare Workers that decouples request handling from background work (webhooks, emails, crawling, buffering writes to APIs or R2). Queues targets at-least-once delivery, no egress charges, and integration with producer and consumer Workers—or HTTP pull consumers outside Workers.

Queues: what you queue and who processes it

Section titled “Queues: what you queue and who processes it”

A queue is a buffer that scales as messages are written; a producer publishes messages; a consumer reads and processes them. Messages are not removed until the consumer acknowledges successful handling (implicitly or with ack()).

Cloudflare Queues is a flexible messaging queue that allows you to queue messages for asynchronous processing.

— Cloudflare, How Queues Works

Queues provides at least once delivery by default in order to optimize for reliability. This means that messages are guaranteed to be delivered at least once, and in rare occasions, may be delivered more than once.

— Cloudflare, Delivery guarantees

Queues does not guarantee FIFO order. For duplicate-sensitive work, use a unique ID in the payload as an idempotency key when calling upstream APIs or databases.

Each queue supports one consumer type: either a push-based Worker (queue handler) or an HTTP pull consumer—not both at once. See Pull consumers and How Queues Works.

max_batch_size and max_batch_timeout: how batching works

Section titled “max_batch_size and max_batch_timeout: how batching works”

When a consumer Worker is bound to a queue, batching controls how many messages arrive per invocation and how long the queue waits to fill a batch. You configure batching when connecting the consumer to the queue—for example in Wrangler configuration or via Configure Queues.

When configuring a consumer Worker for a queue, you can also define how messages are batched as they are delivered.

— Cloudflare, Batching, Retries and Delays

Batching helps in three practical ways:

  • Fewer consumer invocations (cost and cold-start overhead).
  • Grouping writes to external APIs or databases.
  • Spreading load when producers track user-facing traffic.

Whichever limit is hit first delivers the batch

Section titled “Whichever limit is hit first delivers the batch”

max_batch_size and max_batch_timeout work together:

Setting Default Minimum Maximum
max_batch_size 10 messages 1 100
max_batch_timeout 5 seconds 0 s 60 s

Both max_batch_size and max_batch_timeout work together. Whichever limit is reached first will trigger the delivery of a batch.

— Cloudflare, Batching, Retries and Delays

Example: max_batch_size = 30 and max_batch_timeout = 10 delivers 30 messages as soon as 30 are queued; if 30 messages take longer than 10 seconds to arrive, the consumer gets whatever count is on the queue (between 1 and 29).

Tune batching for latency (how long can messages wait?), downstream batch size, and cost (fewer, larger batches vs faster partial batches). Tutorials often raise max_batch_timeout—for example 60 seconds when batching crawl URLs to respect Browser Rendering rate limits.

When a queue is empty, a push-based (Worker) consumer’s queue handler will not be invoked until there are messages to deliver. A queue does not attempt to push empty batches to a consumer and thus does not invoke unnecessary reads.

— Cloudflare, Batching, Retries and Delays

Pull-based consumers that attempt to pull from a queue, even when empty, will incur a read operation.

— Cloudflare, Batching, Retries and Delays

ack() and retry(): per-message acknowledgement in a batch

Section titled “ack() and retry(): per-message acknowledgement in a batch”

By default, if processing fails late in a batch, the entire batch can be redelivered. Explicit acknowledgement lets you commit successful messages while retrying only failures—important for non-idempotent steps (API calls, DB writes).

You can acknowledge individual messages within a batch by explicitly acknowledging each message as it is processed. Messages that are explicitly acknowledged will not be re-delivered, even if your queue consumer fails on a subsequent message and/or fails to return successfully when processing a batch.

— Cloudflare, Batching, Retries and Delays

Call msg.ack() after success and msg.retry() for negative acknowledgement without failing the whole handler. Batch helpers ackAll() and retryAll() mirror successful return vs marking the whole batch for retry.

Precedence (first call wins per message):

  1. After ack(), later ack() or retry() on that message are ignored.
  2. retry() then ack() → ack() is ignored.
  3. Per-message ack() / retry() overrides ackAll() / retryAll() for those messages.

max_retries, delivery failure and dead letter queues

Section titled “max_retries, delivery failure and dead letter queues”

If the consumer throws (and messages were not individually acked), the batch is retried. Default platform behavior:

When a message is failed to be delivered, the default behaviour is to retry delivery three times before marking the delivery as failed. You can set max_retries (defaults to 3) when configuring your consumer, but in most cases we recommend leaving this as the default.

— Cloudflare, Batching, Retries and Delays

When a single message within a batch fails to be delivered, the entire batch is retried, unless you have explicitly acknowledged a message (or messages) within that batch.

— Cloudflare, Batching, Retries and Delays

After max_retries, messages are deleted or sent to a dead letter queue (DLQ) if dead_letter_queue is set on the consumer (Dead Letter Queues). Each retry counts as an extra read for Queues pricing.

Retrying messages with retry() or calling retryAll() on a batch will not cause the consumer to autoscale down if consumer concurrency is enabled.

— Cloudflare, Batching, Retries and Delays

delaySeconds: defer delivery on send and on retry

Section titled “delaySeconds: defer delivery on send and on retry”

Delays defer processing—for scheduled work or backpressure (e.g. HTTP 429 from an upstream API). Maximum delay: 24 hours (Batching, Retries and Delays).

On publish (producer binding):

await env.YOUR_QUEUE.send(message, { delaySeconds: 600 });
await env.YOUR_QUEUE.sendBatch(messages, { delaySeconds: 300 });
// delaySeconds: 0 ignores queue-level default delay

Queue-level default via Wrangler when creating/updating a queue: --delivery-delay-secs or delivery_delay on producers (Configure Queues, Wrangler configuration).

On retry (consumer):

msg.retry({ delaySeconds: 3600 });
batch.retryAll({ delaySeconds: 600 });

Default retry delay per consumer: --retry-delay-secs or retry_delay in Wrangler.

Precedence: per-message or per-batch delaySeconds overrides queue defaults; delaySeconds: 0 on send or retry forces immediate eligibility (Batching, Retries and Delays).

Each Message exposes attempts (starts at 1). You can compute delay when calling retry({ delaySeconds })—for example baseDelaySeconds ** attempts as shown in Batching, Retries and Delays.

Producers: Workers, Pages Functions, and HTTP publish

Section titled “Producers: Workers, Pages Functions, and HTTP publish”

Producer Workers bind a queue in Wrangler ([[queues.producers]]) and call send() / sendBatch() (JavaScript APIs, Getting started). Pages Functions support producer bindings only—not queue consumers (Pages bindings).

Messages default to json content type for Workers with compatibility date after 2024-03-18 (queues_json_messages); use contentType: "text" | "bytes" | "json" | "v8" where needed (JavaScript APIs, Compatibility flags).

You can also publish via HTTP from any client with a token that has Queues Edit permission (Publish messages to Queues directly via HTTP, Publish to a Queue via HTTP).

Limits that affect producers (from Limits):

Constraint Value
Message size 128 KB
sendBatch Up to 100 messages, 256 KB total
Per-queue throughput 5,000 messages/s
Queues per account 10,000
delaySeconds Up to 24 hours

Exceeding throughput causes send() / sendBatch() to throw a Too Many Requests error.

Push consumer Workers vs HTTP pull consumers

Section titled “Push consumer Workers vs HTTP pull consumers”

Push (Worker) consumer: Queues invokes your queue(batch, env, ctx) handler when batches are ready; Consumer concurrency can scale concurrent invocations (up to 250 per queue on paid plans per platform limits). One active consumer Worker per queue is the documented best practice for delivery semantics (How Queues Works).

Pull consumer: Any HTTP client pulls with POST .../messages/pull, then acknowledges with lease_id on .../messages/ack (Pull consumers). Useful for consumption outside Workers or when you control pull rate. Pull consumers can reach 5,000 messages/second per queue (Increased limits for Queues pull consumers). Paused queues return 409 queue_delivery_paused on pull (Pause and Purge).

Switching consumer type requires removing the existing consumer configuration first (Pull consumers).

Backlog metrics: how to see queue pressure

Section titled “Backlog metrics: how to see queue pressure”

Realtime backlog fields include backlog_count, backlog_bytes, and oldest_message_timestamp_ms via dashboard, REST, and await env.QUEUE.metrics() (Realtime backlog metrics now available for Queues, Metrics). send() / sendBatch() responses can include metadata.metrics.

  1. Assuming exactly-once delivery — design for at-least-once; use idempotency keys (Delivery guarantees).
  2. No consumer attached — messages expire after the retention period (Getting started).
  3. Failing mid-batch without ack() — redelivers the whole batch, including already-processed messages.
  4. Using forEach with async work — prefer for...of or Promise.all in the consumer (JavaScript APIs).
  5. Pull consumer + v8 content type — pull consumers cannot decode v8; prefer json, text, or bytes (Pull consumers).
  6. Two consumer types on one queue — only one push Worker or pull configuration per queue.
  7. Expecting Pages Functions to run queue() — use a separate Worker consumer (Pages Functions Wrangler configuration).
  1. In the Cloudflare dashboard Queues page, open your queue and review realtime backlog and the Messages tab (List previews without acking).
  2. Deploy producer and consumer bindings per Getting started, then run npx wrangler tail and trigger your producer to confirm the queue handler logs batches.
  3. After sends, call await env.YOUR_QUEUE.metrics() and confirm backlogCount moves as expected (Realtime backlog metrics).
  4. If using HTTP pull, test messages/pull and messages/ack with a token that has queues_read and queues_write (Pull consumers).
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact wording you are asking about.