Prompt
How do I debug why messages are delayed?
Latest observation
Oct 31, 2026
OpenAI APIWeb search: off
To debug why messages are delayed, first narrow down where the delay is happening:
1) Measure each stage
Track timestamps at these points:
- Producer send time
- Broker/queue receive time
- Consumer start processing time
- Consumer finish time
- Ack/commit time
This tells you whether the delay is:
- before the message reaches the broker,
- in the queue,
- waiting for a consumer,
- or during processing.
2) Check queue depth and consumer lag
If messages are piling up:
- queue length is increasing
- consumer lag is growing
- consumers may be too slow or too few
Look for:
- underprovisioned consumers
- autoscaling delays
- blocked consumers
- high retry rates
- dead-letter queue growth
3) Inspect broker health
Possible broker-side causes:
- disk I/O saturation
- network latency
- partition imbalance
- leader elections / failovers
- quota throttling
- connection churn
- memory pressure
Check broker logs and metrics around the delay window.
4) Look at consumer behavior
Common consumer causes:
- long processing time
- batching too aggressively
- synchronous downstream calls
- lock contention
- thread pool exhaustion
- GC pauses or CPU throttling
- retries/backoffs causing head-of-line blocking
5) Verify message ordering or partitioning
If using partitions or shards:
- one hot partition can delay all messages assigned to it
- key skew can create uneven load
- strict ordering can force serialization
6) Check timeouts and retries
Delays can come from:
- retry policies with exponential backoff
- broker visibility timeouts
- long poll intervals
- delayed acknowledgements
- client-side buffering
7) Correlate logs with tracing
Add or inspect:
- message IDs
- correlation IDs
- trace spans
- timestamps in logs
Then compare producer, broker, and consumer logs for the same message.
8) Reproduce under load
Test with:
- small controlled message bursts
- increasing throughput
- intentional slow consumers
This helps identify the threshold where latency starts growing.
9) Common symptoms and likely causes
- Low throughput, high queue depth → consumers too slow or too few
- Spiky delays → GC, deploys, failovers, autoscaling
- Only some messages delayed → partition imbalance or hot keys
- Delays after retries → downstream dependency issue
- Delays with no queue buildup → producer-side buffering or network issues
10) What to add if you don’t already have it
Add metrics for:
- enqueue-to-dequeue latency
- end-to-end latency
- consumer processing time
- retry count
- queue depth / lag
- broker publish/ack latency
If you want, I can help you debug this for a specific system like Kafka, SQS, RabbitMQ, Pub/Sub, or ActiveMQ.