Skip to content

Lesson 8 of 9 · 24m

Measuring Backlog and Worker Health

Instrument depth, age, throughput, retry rate, and consumer lag so queue problems are visible before customers feel them.

Queue depth alone is a vanity metric. A depth of 50,000 can be fine if workers drain it in twenty seconds; a depth of 20 can be catastrophic if each job takes ten minutes. The question users care about is latency: how long until work is done? Measure backlog as time, not just count.

The minimum useful metrics

For every queue or consumer group, collect:

messages_ready              waiting work count
messages_in_flight          leased but unfinished work
oldest_message_age          worst waiting latency
enqueue_rate                arrival pressure
processing_rate             completed work per second
error_rate                  failures per second
retry_rate                  repeated work per second
dlq_depth                   terminal failure count
consumer_lag                log systems: offset distance
processing_duration         p50/p95/p99 worker latency

The ratios matter as much as the raw values. If enqueue rate exceeds processing rate for long enough, depth grows linearly and recovery time becomes an incident-planning question.

Backlog time is the operator's metric

Estimate how long the current backlog takes to drain:

drain_seconds = ready_messages / max(processing_rate - enqueue_rate, 0.001)

This is a rough model, not physics. It assumes stable rate and uniform job cost. Still, it beats staring at a count. Pair it with oldest message age, which reveals whether work is actually starving.

Instrument the lifecycle

Emit structured events at receive, start, heartbeat, success, retryable failure, permanent failure, acknowledgement, and dead-letter:

{
  "event": "job_retry_scheduled",
  "queue": "billing-email",
  "job_id": "01J9ZK5V0B4T4P7S5H7M0HCEEW",
  "attempt": 3,
  "delay_seconds": 22.4,
  "error_class": "smtp_timeout",
  "worker_version": "2026.11.30-4"
}

That record lets you answer the questions incidents actually ask: which worker version started failing, which dependency caused it, and whether the backlog is new work or repeated old work.

Health checks should reflect work completion

A worker process can be alive and useless. Its HTTP health endpoint says 200 while every job times out against the database. Use a heartbeat job or synthetic canary that verifies end-to-end progress. At minimum, track last successful processing timestamp per queue.

Alert on user impact, not noise

Good paging alerts include oldest age beyond a service-level objective, sustained negative drain rate, or sudden DLQ growth. Ticket-level alerts can cover elevated retry rate or consumer count dropping.

- alert: BillingQueueBacklogSLO
  expr: oldest_message_age_seconds{queue="billing-email"} > 300
  for: 10m

Do not page on every transient retry. Do page when customer-visible work is late and the system is not recovering.

Field notes

  • Percentiles hide poison messages. Track maximum processing duration or oldest in-flight age too.
  • A spike in completed jobs can be bad if they are completing as failures. Label success and failure separately.
  • In-flight count can look healthy while messages are leased to dead workers. Lease expiry metrics matter.
  • Dashboards need queue-specific SLOs. Email, video encoding, and ledger posting do not share the same urgency.

Was this lesson helpful?

Sign in to rate