Diagnose Why a Background Job Queue Is Backing Up From Arrival Rate, Job Duration, and Worker Health

You are helping me diagnose why a background job queue is backing up. Work from the data I give you. Don't assume a cause before checking it against the numbers.

I will provide some of the following: queue depth over time, enqueue rate, dequeue/completion rate, number of workers and their concurrency settings, job duration percentiles (ideally per job type), retry and failure counts, recent deploys or config changes, and the state of downstream dependencies (database, external APIs).

Work through these steps in order and show your reasoning at each one:
1. Arrival vs capacity: estimate throughput capacity as (active workers × concurrency) ÷ average job duration, and compare it with the arrival rate. Say whether the backlog is explained by arrival exceeding capacity, and since when.
2. If capacity looks sufficient on paper, check whether workers are actually busy: look for workers stuck on long or hung jobs, missing timeouts, workers crashing and restarting, prefetch settings that let one worker hoard jobs, or workers subscribed to the wrong queue.
3. Check retries: are failed jobs re-enqueued fast enough that retries crowd out new work? Estimate what fraction of current throughput is retries.
4. Check the job mix: did a new or changed job type with much longer duration start dominating? Compare duration percentiles before and after the backlog began.
5. Check downstream: is job duration rising because a dependency slowed down? Would adding workers make that dependency worse?
6. Check for one-off spikes: a bulk import or scheduled fan-out that will drain on its own given current capacity. Estimate the drain time.

Then give: the most likely cause with the evidence for it, the alternatives you could not rule out and the single measurement that would separate them, a safe immediate mitigation, and a longer-term fix. Explicitly warn if the obvious mitigation (more workers) would overload a constrained dependency.

---

When to use it: when a queue alert fires, users report delayed emails/exports/notifications, or queue depth grows steadily over days. It works with any queue system because it reasons from rates and durations rather than product-specific internals.

How to adapt it: name your queue technology and its relevant settings (visibility timeout, prefetch/ack behavior, retry backoff) so the model can reason about them concretely. If you have per-job-type metrics, include them. They are usually the fastest route to the cause.

Example input: depth rose from near zero to 40,000 over six hours; arrival steady at about 50 jobs/s; 20 workers × 4 concurrency; median duration rose from 0.8 s to 2.5 s after a deploy that added a call to a reporting API; retries up fivefold.

Good output: capacity fell from about 100/s to about 32/s, below the 50/s arrival rate, which explains the growth. The duration increase lines up with the deploy and the new API call. Retries are compounding the problem. Recommended mitigation: put the new call behind a flag or a timeout before adding workers, and check whether the reporting API is rate-limiting. The output then says what single metric would confirm this.

Sign in to upvote this prompt.