Free ops runbook · Queue operations

Queue backlog: retries, DLQ and the poison message

A growing queue is not one problem. A slow consumer, a burst that outruns capacity, a poison message that fails on every attempt, and a retry loop that hammers the database all look identical on a depth chart. The first job is to tell them apart before you add workers or raise a limit.

This page is free. It covers which queue metrics actually move, how visibility timeouts and retry counts turn one bad message into a backlog, and the dead-letter configuration that keeps a failure visible instead of silent.

Scope: reviewed from vendor documentation, no live reproduction
Verified against the Amazon SQS and Cloudflare Queues documentation on 2026-11-26. Metric names and limits are examples from those platforms; command output is the expected shape, not a capture from a live queue. Check the limits for your own plan and region.
Read the backlog

Four numbers, four different problems

Visible depth

Messages waiting to be received. It rises with traffic and falls with capacity, so on its own it cannot tell a spike from a stall.

In-flight depth

Messages delivered but not yet deleted. If this stays high while visible depth falls, consumers are receiving and failing, not catching up.

Age of the oldest

The only metric that maps to user-visible latency. A shallow queue with a ten-minute-old message is worse than a deep queue that drains in seconds.

Dead-letter depth

Failures that exhausted their retries. Any sustained value above zero is data loss waiting for a retention window to expire.

Detect

Separate slow from stuck

Command or viewWhat it tells you
aws sqs get-queue-attributes --queue-url "$Q" --attribute-names ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible ApproximateAgeOfOldestMessageThe three depths and the age, in one call. Values are approximate and can lag by about a minute.
aws sqs get-queue-attributes --queue-url "$DLQ" --attribute-names ApproximateNumberOfMessagesWhether failures are accumulating where nobody is looking.
npx wrangler queues list and the queue's metrics viewCloudflare Queues backlog and consumer health for the same window.
npx wrangler tail YOUR_WORKER --status errorThe actual exception the consumer is throwing, not just the count.
Consumer logs: message id, attempt number, handler durationWhether the same message id repeats (poison) or many ids fail once (dependency down).
Database: connection count, lock waits, p99 write latencyWhether the queue is the cause or the symptom of a saturated downstream.
Failure modes

Seven ways a backlog stops draining

#Failure modeWhat you seeWhat to do
1Visibility timeout shorter than the handlerThe same message is delivered twice; logs show two attempts overlapping for one id; duplicate side effects.Measure p99 handler time and set the timeout above it, then make the handler idempotent on a business key, not just on the message id.
2No retry capOne message returns to the queue forever; depth never reaches zero even with idle consumers.Set a maximum receive count below the dead-letter threshold and alarm on the DLQ, not on total depth.
3A dead-letter queue nobody readsThe DLQ fills silently and its retention window deletes the evidence before anyone investigates.Alarm on any DLQ message, set retention longer than your response time, and document the redrive command.
4Immediate in-process retriesCPU and database connections spike while the queue depth is flat; retries exhaust the dependency instead of waiting.Retry with exponential backoff and jitter, or return the message to the queue and let the visibility timeout provide the delay.
5Scaling consumers to the backlogWorkers double, the downstream saturates, and every consumer starts timing out; the queue grows faster.Scale on the downstream's healthy capacity, cap concurrency, and use batch size to trade throughput for per-message latency.
6FIFO group head-of-line blockingOne tenant's messages stall while other groups drain; the poison message blocks its whole group.Keep message groups small, cap attempts per group, and move a repeatedly failing message out so the group can advance.
7Reading depth as latencyDashboards look calm while users wait minutes; or a scary spike clears in seconds.Alert on age of the oldest message and on consumer error rate, and use depth only as context.
Design

Make failure a state, not a loop

DecisionQuestion to answer
IdempotencyWhat business key makes a second delivery harmless: order id, event id, a unique constraint?
AttemptsHow many receives before the message is parked, and is that number lower than the visibility-timeout math assumes?
BackoffDoes a failed attempt wait, or does it return immediately and multiply the load?
DLQWho is paged, what is retained, and what is the tested redrive path back to the main queue?
IsolationCan one tenant or one message group consume the capacity meant for everyone else?
Verify

Three drills before the incident

Drain test

Publish a known batch, stop consumers, restart them, and record how long the queue takes to reach zero and what the oldest age does. That is your real throughput, not the vendor's number.

Poison test

Publish one message the handler always rejects. Confirm it lands in the DLQ after the configured attempts, that the alarm fires, and that the rest of the queue keeps draining.

Redrive test

Move the poisoned message back after a fix and confirm it is consumed once, with no duplicate side effect.

Duplicate test

Deliver the same message twice on purpose and confirm the handler's unique constraint or dedupe table absorbs the second delivery.

FAQ

Questions from the on-call channel

Should we just add more consumers?

Only if the downstream has headroom and the message age is falling. If in-flight depth is high and error rate is rising, more consumers multiply the failure. Fix the handler or the dependency first.

Why does the depth drop and then come back?

That is the visibility timeout cycling: messages are received, the handler fails or is too slow, and they become visible again. Depth looks like progress while nothing is being deleted.

Is a dead-letter queue a backup?

No. It is a holding area with a retention limit and no ordering guarantee. Treat it as evidence plus a redrive source, and alarm on the first message.

Do FIFO queues remove the need for idempotency?

No. They reduce duplicates within a deduplication window and preserve order per group, but a handler that times out after doing its work can still be retried. Keep the business-key check.

Sources

Primary sources

Going deeper on the change window?

The paid runbooks cover the surrounding failures: cache rules that hide a deploy, AI gateway timeouts, and platform defaults that only bite on a real domain.

This page is free, no checkout. Paid runbooks are $9.99 each and covered by the 7-day refund policy at /runbooks/refund.