Reliable background jobs: queues, retries and idempotency
How to move slow or flaky work out of the request cycle and make it safe to retry.
API calls to LLMs, email providers or payment gateways can be slow or fail intermittently. Running them inside a web request makes your application feel unreliable. A job queue gives you a better model.
Queue the work
Accept the request, store the intent, return quickly and let a worker process the job. Queues such as BullMQ on Redis provide delays, concurrency control and visibility into job state.
Retry with backoff
Transient failures are normal. Retry with exponential backoff, cap the number of attempts and move permanently failing jobs to a dead-letter state you can inspect.
Make jobs idempotent
A retried job must not charge a customer twice or send the same email twice. Use idempotency keys and check state before acting, so running a job again is always safe.
Written by DevFlowX Team