Skip to content

Queue-depth monitoring — the metric that actually predicts incidents

How to monitor message-broker queue depth in a way that catches real problems — what to alert on, what to ignore, and the dashboards an MSP wires up on day one.

Queue depth is the single most predictive metric for a message-broker incident — when consumers fall behind, depth grows; when depth grows past a threshold, downstream services start timing out. This article is the queue-depth monitoring posture we wire for clients on day one: what metric to collect from each broker, the threshold shape that catches real problems without paging on every blip, and the dashboards that turn a noisy stream of numbers into an operator signal.

How to verify

The metric is named differently in each broker. Confirm what you have:

# RabbitMQ — per-queue depth via management API
curl -u admin:PASS http://rabbitmq:15672/api/queues/%2F/q.orders | \
  python3 -c "import json,sys; d=json.load(sys.stdin); print(d['messages'], d['messages_ready'], d['messages_unacknowledged'])"

# Kafka — consumer lag from kafka-consumer-groups
/opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
  --describe --group orders-consumer | awk 'NR>1 {sum+=$6} END {print "total_lag="sum}'

# JetStream — per consumer pending count
nats consumer info ORDERS process-orders | grep -E 'Num Pending'

# SQS — ApproximateNumberOfMessages
aws sqs get-queue-attributes --queue-url $URL \
  --attribute-names ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible

# Sidekiq — queue size per queue
redis-cli LLEN queue:default
redis-cli ZCARD schedule
redis-cli ZCARD retry

If any of these returns a non-zero value that you cannot explain, your dashboard does not exist yet.

What’s happening

Queue depth is a leading indicator. By the time downstream services are timing out, the broker has been backing up for minutes. Alert on depth and you catch the problem before the customer does; alert on downstream errors and you catch it after.

What depth actually means depends on the broker:

  • RabbitMQ. messages = total in the queue (ready + unacknowledged). messages_ready = waiting for a consumer. messages_unacknowledged = delivered but not yet acked. The _ready number is what consumer scaling fixes; the _unacknowledged number rising means consumers are slow or stuck.
  • Kafka. Per consumer group, per partition: lag = log-end-offset - committed-offset. Total lag is the sum across partitions. A consumer that never commits has lag equal to total messages ever produced — a useful signal that the consumer is broken, not just slow.
  • JetStream. Per consumer, num_pending = messages on the stream that this consumer has not yet processed. Similar to Kafka lag.
  • SQS. ApproximateNumberOfMessages = waiting to be received. ApproximateNumberOfMessagesNotVisible = received but not deleted (in-flight). Rising NotVisible means the visibility timeout is masking failures.
  • Sidekiq. LLEN queue:<name> for each queue, plus ZCARD schedule and ZCARD retry. The retry set growing means workers are failing.
  • BullMQ. bull:<queue>:waiting (LLEN), bull:<queue>:active (LLEN), bull:<queue>:failed (ZCARD).

The shape of the metric matters more than the absolute value. A constant depth of 500 on a queue processing 1000 messages per second is healthy (0.5s of buffering). A depth of 100 on a queue that usually processes 1 per second and is now empty is a sign that the producer has stopped. Context, not thresholds, drives the alert design.

What to alert on

Static high threshold is the wrong default. It alerts on every quiet hour with a small backlog, ignores a real outage in a high-volume queue, and gets tuned upward into uselessness within a month.

The patterns that actually work:

  1. Rate-of-change. “Queue depth growing for 5 consecutive minutes” catches a consumer that has stopped without paging on a normal traffic spike. In PromQL: deriv(rabbitmq_queue_messages_ready[5m]) > 100.

  2. Backlog age, not count. “Oldest unprocessed message is older than 60 seconds.” Many brokers expose this directly (Kafka via timestamp on the oldest unconsumed offset; RabbitMQ via a derived metric); for the rest, instrument it at the consumer.

  3. Multi-window comparison. “Depth is now 3x the trailing 1-hour average.” Catches anomalies without needing a hand-tuned threshold.

  4. Hard ceiling. A static threshold IS valid as a backstop — “depth > 100,000 page immediately, no matter the rate.” This catches the case where rate-of-change alerting fails because the depth was already huge when monitoring started.

  5. Worker-side liveness. “Number of active consumers < expected” alongside depth. A growing queue with no consumers is unambiguous; a growing queue with consumers is “they are slow”; a flat queue with no consumers is “no work to do” — completely different incidents.

The dashboards

For each queue or topic worth alerting on, the dashboard panel shows:

  • Queue depth over time (line chart, last 24h).
  • Produce rate vs consume rate over time (two lines, ideally tracking each other).
  • Number of active consumers / workers (count, with expected baseline).
  • DLQ depth (separate small panel — see dead-letter queues).
  • Oldest message age (if the broker exposes it).

The producer/consumer rate panel is the single most informative chart. When they track each other, the system is healthy. When produce rate spikes and consume rate does not follow, you see the backlog forming in real time and can scale workers before the depth alert fires.

The runbook

When a depth alert fires, the operator’s first three questions:

  1. Are consumers alive? Check the consumer count metric. Zero consumers means a deployment failure, a connection issue, or a worker pool that crashed. Restart the workers, then investigate.
  2. Are consumers slow or broken? Check the retry / DLQ counters. A growing DLQ alongside a growing queue means a poison message is causing crashes; a growing queue with no DLQ growth means the work is just slow.
  3. Is the producer faster than expected? Compare produce rate to its baseline. A 10x produce-rate spike with normal consumers is a capacity event — scale workers, not the broker.

The third case is where pre-built scaling helps: a queue-depth-driven autoscaler (KEDA on Kubernetes, an ASG metric in AWS) adds worker capacity automatically. Without it, the operator does the math and scales manually.

Operational notes

  • Per-queue alerting is more useful than aggregate alerting; 200 messages on the payments queue is a different incident than 200 messages on the analytics-ingest queue.
  • Sampling interval matters — a queue can spike and drain inside a 60-second scrape interval. For high-rate queues, scrape every 15-30 seconds.
  • Beware “ready vs unacknowledged” confusion in RabbitMQ — a stuck consumer holding 10,000 unacked messages looks like a healthy queue with messages_ready=0 if you only graph the ready count.
  • The Kafka LAG metric is per-group; a new consumer group with auto.offset.reset=latest starts with lag = 0 even if there are 10 million messages on the topic. The metric is honest about what that consumer has not seen.
  • DLQ depth is its own metric, alerted on separately from main-queue depth — they have different operational meanings.

Stack Harbor wires queue-depth monitoring as part of any messaging onboarding — broker-specific exporters (rabbitmq-exporter, kafka-exporter, nats-exporter, sidekiq-prometheus-exporter), dashboards in the same Grafana that hosts the rest of the platform, and rate-of-change alerts tuned to each queue’s traffic pattern. This is the work covered by our Managed Operations practice.