Group
  • Performance

    Add backpressure to my background job queues

    Keep slow jobs from silently piling up into a multi-day backlog with limits, monitoring, and overload behavior.

    • Plan & validate
    • Automate workflows
    • Advanced
    • General

Free Prompt

My app queues background jobs (emails, image processing, report generation, third-party API calls). Jobs usually process fine, but I've never checked what happens when jobs arrive faster than workers can handle them. Make my queues safe under overload: 1. Measure the baseline: jobs enqueued per minute at normal load, average job duration, and worker throughput. From that, calculate how much headroom I have and how fast a backlog grows when the producer outpaces the workers (a job that takes 2 seconds with one worker clears 30/minute; anything above that is a growing queue). 2. Add visibility: queue depth and age-of-oldest-job metrics, with an alert when depth or age crosses a threshold. A queue that silently grows for days turns a small hiccup into users getting welcome emails three days late. 3. Define overload behavior per job type: - Shed or defer non-urgent work (analytics, cleanup) when the queue is deep. - Coalesce duplicate jobs (five 'reindex user X' jobs can become one). - Keep user-facing-critical jobs (purchase receipts, password resets) prioritized, on a separate queue if needed, so a report-generation spike doesn't delay receipts. 4. Bound retries: cap retry counts, use exponential backoff, and send permanently failing jobs to a dead-letter queue I actually check, instead of retrying forever and clogging the worker. 5. Fix the producers: jobs enqueued in loops per-user or per-row (send this email to 50,000 users) should be batched or rate-limited so one action can't flood the queue. Don't just add more workers as the plan; if the job hits a shared resource (database, third-party API), more workers move the bottleneck and can take the database down with it. The deliverable is the throughput math, the monitoring and alerts, the per-type overload behavior, and the retry/dead-letter setup.

What This Does / How This Helps

This measures your queue's real throughput, adds depth and age monitoring, defines what happens under overload per job type, and bounds retries with a dead-letter queue. Queues fail silently. There's no error page; work just happens later and later, and you find out when a user asks why their export never arrived or a customer gets a receipt email six hours after purchase. The producer-outpaces-worker situation is also guaranteed to happen eventually: one bulk action, one retry storm from a flaky third party. Backpressure and monitoring turn an invisible, compounding failure into a boring alert you handle in minutes.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts