Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
Python & Django

Work That Happens Outside a Request

Last updated:

What belongs in a queue

  • External API calls, which can be slow and can fail
  • Email and notifications
  • Report and document generation
  • Data processing of any size
  • Anything the user does not need to wait for
A web request should do the minimum required to respond. Everything else belongs behind a queue, where it can be retried without the user knowing.

Task design

  1. Idempotent — running twice must not double the effect
  2. Small arguments — pass identifiers, not whole objects
  3. Bounded retries, with backoff
  4. Explicit timeouts, so a stuck task does not hold a worker forever
  5. Logged, with a correlation identifier from the originating request

Monitor the queue, not just the workers

SignalMeans
Queue depth growingWorkers stopped or too few
Task duration increasingSomething is degrading
Failed queue growingSomething is systematically wrong
Zero tasks processedWorkers are not running
Retries increasingAn external dependency is struggling

Queue depth is the single most useful monitor in a queued system, and it is frequently the one nobody set up.

The failed task queue needs an owner

Most systems have a dead letter queue that was built during development and has never been checked. Work fails, lands there, and stays.

Somebody should look at it regularly, and it should alert when it grows. Otherwise it is a silent hole where work disappears.

Workers need supervision

A worker process that exits leaves work accumulating with no error anywhere visible. It needs a process supervisor to restart it and monitoring to notice if it does not.

That is basic operational plumbing and it is what separates a system that recovers from one that quietly stops.

Frequently asked questions

Which task queue should we use?

The established options are all capable. Choose on operational familiarity rather than feature comparison.

Can we use the database as a queue?

At modest volume, yes, and it is simpler to run. Dedicated brokers earn their place at higher throughput.

How many workers do we need?

Enough to keep the queue draining at peak. Measure rather than guess, and alert on depth.

What about long-running tasks?

Break them into smaller ones where possible. A task running for an hour is hard to retry and hard to monitor.

Keep reading

Requests timing out on slow work?

That work belongs in a queue. Usually a contained change with an immediate effect.

Book a free 30-minute call Get a project estimate WhatsApp us

Related services

What we build for problems like this one

Custom Software DevelopmentWeb DevelopmentMachine Learning