Deployment Guides
Background Jobs and Queues: When Request-Response Isn't Enough
Emails, exports, LLM calls, and imports don't belong in request handlers. How to add a job queue properly: retries, dead letters, idempotency, and monitoring.
By AI Production Partner · · 3 min read
The smell: slow requests doing heavy work
Sending email, generating PDFs, calling LLMs, processing uploads, syncing third-party data — none of it belongs in a request handler. Done inline, it makes users wait, times out under load, and fails unrecoverably when anything hiccups. The fix is old and universal: put the work on a queue, return immediately, process in the background with retries. AI-generated apps almost never include this layer, because the inline version works in the demo.
The queue done right
Pick the boring option for your stack (BullMQ for Node, Celery for Python, Sidekiq for Ruby, or your cloud's native queue) and apply the four disciplines: retries with exponential backoff for transient failures; a dead-letter destination for jobs that keep failing (so they're investigated, not vaporized); idempotent job design, because retries mean everything eventually runs twice; and timeouts so a hung job doesn't block a worker forever.
Give workers their own deployment lifecycle and monitoring — queue depth, job failure rate, and processing lag are the three numbers that predict trouble before users feel it.
The LLM special case
Apps with AI features need queues more than most: model calls take seconds, fail transiently, and cost money per attempt — exactly the profile background jobs exist for. Queue the calls, cap retries with budget awareness, and stream or notify results back to users instead of holding requests open.
Adding a proper job layer is a recurring first-month task in our productionization engagements — it's where reliability and user experience improve in the same move.