Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
  1. Home
  2. Blog
  3. Work That Happens Outside a Request
Python & Django

Work That Happens Outside a Request

Background processing in Python with task queues and workers: idempotent tasks, bounded retries, queue depth monitoring and owning the failed task queue.

Updated 2 min readBy SpiderHunts Technologies

Free estimateNo obligation

Get a free estimate

Tell us what you need. A senior engineer reads every enquiry.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →

Quick answer — TL;DR

Queue anything slow or unreliable. Make tasks idempotent, bound the retries, monitor queue depth, and check the failed task queue — most systems build it and never look at it.

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.

FAQ

Frequently asked questions

The questions readers ask us after this guide.

Still have a question?

Ask us directly — a senior engineer will get back to you.

Ask about your project

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

More on Python & Django

Python & Django

An API Other Systems Can Depend On

Designing a Python API service others can depend on: validation at the boundary, consistent errors and status codes, early versioning and documentation.

Python & Django

Moving and Transforming Data Reliably

Building data pipelines in Python that cope with malformed input: restartable stages, quarantining failures, reconciling counts and alerting on absence.

Start here

Requests timing out on slow work?

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

  1. You tell us what you needTwo minutes on the form, or a message on WhatsApp.
  2. A senior engineer reviews itAnd comes back with questions, a realistic range and an honest view on fit.
  3. Free 30-minute scoping callWe talk through scope, options and a realistic estimate — with no obligation.
Free estimateNo obligation

Talk to someone who builds this

Send a short brief and we will come back with an honest view and a realistic range.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →