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

Work That Should Not Block a Request

Django background tasks for email, API calls, reports and bulk jobs: idempotent design, transaction pitfalls, queue monitoring and failed task ownership.

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

Email, external API calls, report generation and bulk operations all belong behind a queue. Make tasks idempotent, monitor queue depth, and check the failed task queue.

What belongs in a queue

  • Email and notifications
  • Calls to external systems
  • Report and document generation
  • Bulk operations across many records
  • Anything taking more than a moment
Sending email during a request is the most common cause of a slow form submission and of a form that appears to fail when it actually succeeded.

Task design

  1. Pass identifiers, not objects — the record may change before the task runs
  2. Idempotent — a retry must not double the effect
  3. Bounded retries with backoff
  4. Explicit timeouts
  5. Logged, with the originating request identifier

Watch out for transactions

A task queued inside a database transaction may start before the transaction commits, and then fail to find the record it was given.

Queue tasks after the transaction commits. Django provides a hook for exactly this, and it prevents a class of intermittent failure that is difficult to diagnose.

Monitor the queue

SignalMeans
Depth growingWorkers stopped or too few
Failed queue growingSomething systematically wrong
Zero tasks processedWorkers not running
Duration increasingSomething degrading
Retries increasingAn external dependency struggling

The failed queue needs an owner

Most applications have a dead letter queue built during development and never checked. Work fails, lands there, and stays there indefinitely.

It should alert when it grows and somebody should review it regularly. Otherwise it is a silent hole where work disappears.

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 with Django?

The established options integrate well. Choose on operational familiarity rather than feature comparison.

Can we use the database as a broker?

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

How do we test tasks?

Run them synchronously in tests, and separately test that they are queued when expected.

What about scheduled work?

A scheduler that enqueues tasks, so scheduled work gets the same retries and observability as everything else.

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

Forms that take five seconds to submit?

It is usually email or an external call in the request. Moving it to a queue is a contained change.

  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 →