Django's Native Background Tasks Are a Good Step. Celery and Redis Are Still More Complete.
Django now ships its own background tasks. My view: a good step that will save infrastructure cost for simple apps, while Celery and Redis stay the way to go for complex systems. Here are the facts behind that view, and a hands-on guide.
DILJOT SINGH · TECHNICAL LEADOpinion. The facts are sourced and linked; the views are mine.
Django finally has background tasks built in. Django 6.0, released on 3 December 2025, added django.tasks, a standard way to run code outside the request–response cycle (Django 6.0 released). Django 6.1 refined it on 5 August 2026 (Django 6.1 release notes).
I think this is a good step for Django. I also think Celery with Redis is still more complete, and for complex systems it's still the way to go. Where Django's native tasks really matter is simple applications. For those I expect real savings at the infrastructure level, because fewer servers and services are needed.
This piece explains that view with the facts behind it:
- ▸what was added
- ▸how the architecture changes compared with Celery and Redis
- ▸where the cost saving comes from
- ▸why I think this choice matters more now that so much code is written with AI assistants
The second half is a hands-on guide, checked against Django 6.1. The short version lives in the Background tasks card of my Django cheat sheet.
The facts: what Django added
- ▸What's new: a built-in Tasks framework,
django.tasks. You define a task with@task, queue it with.enqueue()and read its status and result later. The backend that stores and runs tasks is chosen in theTASKSsetting (Django's Tasks framework). - ▸When: Django 6.0 (3 December 2025). Django 6.1 (5 August 2026) lets the
@taskdecorator pass extra options to the backend, and lets tasks and results be pickled. - ▸Who: Jake Howard proposed the feature in DEP 14, "Background workers" (created February 2024, shepherded by Carlton Gibson) and implemented it. The 6.0 release post credits it to him.
- ▸What it doesn't do: Django does not include a production worker. Its two built-in backends are for development and testing. In production a backend package supplies the queue and the worker process (Configuring a Task backend).
- ▸On older Django: the same API is available for Django 4.2 to 6.0 through the
django-tasksbackport.
Why it's a good step
Native support fixes a real gap. DEP 14 gives two reasons for adding it:
- ▸Django had no first-party answer for long-running work, while frameworks such as Laravel have background workers built in.
- ▸Every library that wanted to push work into the background had to support each task queue separately. That cost fell on small packages and on large ecosystems such as Wagtail alike.
With one standard interface, code and libraries are written once against django.tasks, and each project decides which backend runs the work. Moving to another backend becomes a settings change rather than a rewrite. The default backend even runs tasks inline, so a project can be written with tasks from day one, before any queue infrastructure exists (Immediate execution).
The framework is also deliberately cautious. The DEP originally said Django would ship backends useful for testing, local development and production. What landed in 6.0 has only the development and testing backends built in, and production backends come from packages.
Where the saving comes from: before and after
My cost argument is easiest to see as architecture. Here is a typical Celery setup next to Django tasks on a database backend.
In a typical Celery deployment:
- ▸The web app sends each task to a broker, usually Redis or RabbitMQ.
- ▸One or more Celery worker processes take tasks from the broker and run them.
- ▸Periodic jobs need Celery beat, a separate scheduler process. Celery's docs warn that only one scheduler may run for a schedule (Periodic Tasks).
That's a broker to host, secure, monitor and back up, plus two kinds of Celery process.
With Django tasks and the django-tasks-db backend:
- ▸The queue is a table in your existing database.
- ▸The worker is
python manage.py db_worker: the same codebase and settings, started as a second process. - ▸There is no broker.
| Before: Celery + Redis | After: django.tasks + django-tasks-db | |
|---|---|---|
| Services to run | Web, Redis, Celery worker, Celery beat (if scheduling), database | Web, db_worker, database |
| Where queued work lives | Redis (the broker) | A table in your database |
| Task API | Celery's own (.delay(), @shared_task) | Django's (@task, .enqueue()) |
| Periodic jobs | Celery beat | Cron or your platform's scheduler |
| Retries, workflows, routing | Built in | Depends on the backend; basic today |
| Swap the queue later | Rewrite call sites | Change TASKS in settings |
Each service in the "before" picture is something to provision, pay for, secure, monitor, patch and back up. The "after" picture removes the broker and the scheduler process. For a simple application, that's three moving parts instead of five. This is why I think simple apps will save money at the infrastructure level: fewer servers and services are needed.
The saving is in services, not in compute. The background work still has to run somewhere, and a busy queue still needs enough worker capacity. What disappears is the fixed cost of infrastructure that exists only to move messages around.
Two facts keep the comparison fair:
- ▸Celery doesn't require Redis. Its supported brokers include RabbitMQ, Redis, Amazon SQS, Kafka, Google Pub/Sub and PostgreSQL via PGMQ (Backends and Brokers).
- ▸The database is doing more work. Queued tasks and their results now share the database with your app's own tables.
django-tasks-dbincludes aprune_db_task_resultscommand to delete old results. For very high task volumes, a dedicated broker is still the safer design.
Why Celery and Redis are still the way to go for complex systems
Celery with Redis is still more complete. When background work is the heart of the system, Celery already has what Django's framework leaves to the backend:
- ▸retries with backoff (Retrying)
- ▸a scheduler for periodic jobs (celery beat)
- ▸chains and groups of tasks (Canvas)
- ▸a choice of brokers built for high throughput
Django's framework defines the contract and deliberately stops there (Tasks reference). That is why, for complex systems, I think Redis and Celery are still the way to go.
Why this choice matters more with AI-assisted coding
With AI-assisted coding, I think developers might not think much about this choice. That is very important, because the choice drives cost. A task queue gets added in a few minutes, but the broker and extra processes behind it are paid for every month after that.
So the backend should be a decision a person makes on purpose. Before adding Redis and Celery, answer three questions:
- ▸Do you need retries, schedules or workflows today?
- ▸How many tasks per minute do you expect?
- ▸Is a broker worth running for that?
What I'll be watching
Because this is new, I'm very interested to see how the industry adopts it. The framework is a year old, and the ecosystem around it is young. These are the signals I'm tracking:
- ▸Backends. Django's Community Ecosystem page currently lists four options:
django-tasks-db,django-tasks-rq, thedjango-tasksbackport, and huey (usable as a Tasks backend). - ▸A bridge to Celery. A third-party
django-tasks-celerypackage describes itself as a "Celery backend for Django's task framework". It's at version 0.1.1 (April 2026) and requires Django 6.0 or newer. If bridges like this mature, code written againstdjango.taskscould run on Celery when a project outgrows a simple backend, without rewriting call sites. - ▸Version support. At the time of writing,
django-tasks-db0.13 lists Django 5.2 and 6.0 in its PyPI classifiers, but not 6.1. Check a backend's release notes before upgrading Django. - ▸Library adoption. The DEP's goal was for reusable apps to queue work without picking a queue library. Watch whether large packages start defining their background work as
django.tasks.
Part 2: hands-on. The rest of this piece is a practical guide to django.tasks, for trying it yourself.
How a background task works
Django's docs describe three parts (Background Task fundamentals):
- ▸A Task is a call to one of your functions, plus everything needed to run it later. It gets a unique id.
- ▸The queue store holds tasks until they run. The backend decides what that is: a database table, Redis, or nothing at all.
- ▸A worker is a separate process that claims a task from the queue store, runs it, and saves the status and result back.
What the Tasks framework changes for developers
- ▸One API, whichever queue runs it. Tasks are written with
@taskand sent with.enqueue(). The backend is chosen in theTASKSsetting, so moving between backends is a settings change, not a rewrite (TASKS setting). - ▸Start before the infrastructure exists. The default
ImmediateBackendruns each task straight away, inside the request, so code can be written as tasks from day one and moved to real workers later. The docs give this as the reason the default exists (Immediate execution). - ▸Tests without a broker.
ImmediateBackendruns tasks inline, andDummyBackendrecords them without running them (Dummy backend). - ▸Async support.
aenqueue(),aget_result()andarefresh()work in async views (Asynchronous support). - ▸Signals.
task_enqueued,task_startedandtask_finishedlet you log or measure tasks in one place (Tasks signals).
Step 1: Define a task
A task is a module-level function decorated with django.tasks.task. By convention it lives in the app's tasks.py (Defining Tasks):
# accounts/tasks.py
from django.contrib.auth import get_user_model
from django.core.mail import send_mail
from django.tasks import task
@task(priority=10, queue_name="emails")
def send_welcome_email(user_id):
user = get_user_model().objects.get(pk=user_id)
send_mail(
subject="Welcome aboard",
message=f"Hi {user.first_name}, your account is ready.",
from_email=None, # DEFAULT_FROM_EMAIL
recipient_list=[user.email],
)
return user.email # stored as the result's return_valueThe decorator returns a Task object, not a plain function (task decorator reference):
- ▸
priorityis a number from -100 to 100, where higher runs sooner, if the backend supports priorities. The default is 0. - ▸
queue_namemust be one of the backend'sQUEUES. The default is"default". - ▸
backendnames which entry inTASKSto use. The default is"default". - ▸
takes_context=Truepasses aTaskContextas the first argument, with the currentattemptnumber and thetask_result.
A Task can't be changed after it's defined. .using() returns a copy with a different priority, queue, backend or start time (Modifying Tasks):
urgent = send_welcome_email.using(priority=50)
urgent.enqueue(user_id=user.pk)Step 2: Enqueue it after the transaction commits
.enqueue() puts the task on the queue and returns a TaskResult straight away:
result = send_welcome_email.enqueue(user_id=user.pk)
result.id # string id, under 64 characters
result.status # TaskResultStatus.READYTwo rules prevent most first-week bugs.
Pass ids, not objects. Arguments and return values go through json.dumps() and json.loads(), so they must be JSON-serializable and come back as the same type. Model instances and datetime objects fail, and a tuple comes back as a list (Enqueueing Tasks). Send the primary key and load the row inside the task.
Enqueue after the commit. Most backends run tasks in another process on another database connection. If you enqueue inside transaction.atomic(), a fast worker can start before the new row is committed and fail to find it. The docs recommend transaction.on_commit() with functools.partial (Transactions):
# accounts/views.py
from functools import partial
from django.db import transaction
from .tasks import send_welcome_email
def signup(request):
...
with transaction.atomic():
user = form.save()
transaction.on_commit(partial(send_welcome_email.enqueue, user_id=user.pk))
return redirect("accounts:welcome") # returns at once; the email is sent by the workerIf the transaction rolls back, the task is never queued. The Transactions card in the cheat sheet covers atomic() and on_commit() in more detail.
Step 3: Check the result
Store result.id if anything needs to check on the task later, such as a progress page. Then read it back from the task or from the backend (Task results):
from django.tasks import TaskResultStatus, default_task_backend
result = send_welcome_email.get_result(result_id) # or default_task_backend.get_result(result_id)
result.refresh() # re-read the latest status from the queue store
if result.status == TaskResultStatus.SUCCESSFUL:
result.return_value # what the function returned
elif result.status == TaskResultStatus.FAILED:
result.errors[0].exception_class # e.g. <class 'smtplib.SMTPException'>
result.errors[0].traceback # the traceback as a stringA result has four statuses: READY, RUNNING, FAILED and SUCCESSFUL. It also records when the task was enqueued, started and finished, how many attempts it took, and which workers ran it. Reading return_value before the task succeeds raises ValueError (TaskResult reference).
get_result() only works where the backend can look results up later. The built-in ImmediateBackend can't, and raises NotImplementedError.
Step 4: Choose a backend for production
The backend decides where tasks are stored and what runs them:
| Backend | Where it comes from | What runs the tasks | Good fit |
|---|---|---|---|
ImmediateBackend | Built into Django (the default) | The request itself, inline | Development, or before a worker exists |
DummyBackend | Built into Django | Nothing; tasks are only recorded | Tests that check what was queued |
django_tasks_db.DatabaseBackend | django-tasks-db | manage.py db_worker | Simple apps that want no extra infrastructure |
django_tasks_rq.RQBackend | django-tasks-rq | RQ workers (rqworker) | Projects that already run Redis |
| huey | huey | Huey's consumer | Redis, SQLite or Postgres queues |
The simplest production setup is the database backend, because it uses the database you already have (django-tasks-db on PyPI):
# settings.py (after: pip install django-tasks-db)
INSTALLED_APPS = [
# ...
"django_tasks_db",
]
TASKS = {
"default": {
"BACKEND": "django_tasks_db.DatabaseBackend",
"QUEUES": ["default", "emails"], # enqueueing to any other queue name fails
}
}python manage.py migrate # creates the task table
python manage.py db_worker # run this as its own long-lived process
python manage.py prune_db_task_results # delete finished results (run on a schedule)Run the worker as a separate service next to the web server: a second process in Docker Compose, systemd or your platform's worker type. In DEBUG mode db_worker reloads when code changes. The package advises against relying on that in production, because tasks may not stop cleanly.
Run a task later with run_after
To delay a task, set run_after through .using(). It takes a timedelta (from now) or a timezone-aware datetime (Task.run_after):
from datetime import timedelta
send_welcome_email.using(run_after=timedelta(minutes=30)).enqueue(user_id=user.pk)Not every backend can defer work. Backends advertise what they support with feature flags: supports_defer, supports_priority, supports_get_result and supports_async_task. ImmediateBackend can't defer, so run_after raises InvalidTask there (Feature flags). Check the flag when code has to work with more than one backend:
from django.tasks import default_task_backend
if default_task_backend.supports_defer:
reminder.using(run_after=timedelta(days=1)).enqueue(order_id=order.pk)run_after delays a single task. It doesn't repeat it, so a nightly job still needs cron or your platform's scheduler to enqueue it.
Testing tasks
Point TASKS at a built-in backend in your test settings, so tests need no worker or broker.
- ▸
ImmediateBackendruns each task inline when it is enqueued. Use it to test the whole flow end to end, withmail.outboxfor emails. - ▸
DummyBackendstores enqueued tasks without running them. Use it to check that something was queued (Dummy backend):
# settings_test.py
TASKS = {"default": {"BACKEND": "django.tasks.backends.dummy.DummyBackend"}}
# accounts/tests.py
from django.tasks import default_task_backend
from django.test import TestCase
class SignupTests(TestCase):
def setUp(self):
default_task_backend.clear() # forget tasks from earlier tests
def test_signup_queues_welcome_email(self):
with self.captureOnCommitCallbacks(execute=True): # run on_commit hooks inside the test
self.client.post("/signup/", {"email": "[email protected]", "password1": "…", "password2": "…"})
self.assertEqual(len(default_task_backend.results), 1)TestCase wraps each test in a transaction that never commits, so on_commit() callbacks don't run on their own. captureOnCommitCallbacks(execute=True) runs them (captureOnCommitCallbacks).
Django Tasks or Celery?
The trade-off from the opinion section above, as a quick decision table:
| If you need… | Reach for |
|---|---|
| Emails, notifications, webhooks and other fire-and-forget jobs in a simple app | django.tasks + django-tasks-db |
| The fewest services and the lowest fixed infrastructure cost | django.tasks + django-tasks-db |
| Code that should not be tied to one queue library | django.tasks |
| Retry policies, periodic schedules, chains and groups, high throughput | Celery (with Redis or RabbitMQ) |
| An existing Celery setup that works | Keep Celery; nothing forces a move |
The two can live side by side. A project can use django.tasks for simple jobs and keep Celery for the pipelines that need it. The Celery card and Celery commands card in the cheat sheet show its setup.
On Django 5.2? Use the django-tasks backport
The same API is available for older versions from the django-tasks package, which Django's docs point to (Tasks framework). Add "django_tasks" to INSTALLED_APPS and import from django_tasks instead of django.tasks. After upgrading to Django 6, switching back is mostly a change of imports and backend paths. Since version 0.12 the backport no longer bundles the database and RQ backends; they are the separate django-tasks-db and django-tasks-rq packages.
Checklist
- ▸Define tasks as module-level functions in
tasks.py. - ▸Pass primary keys and other JSON-safe values, never model instances.
- ▸Enqueue with
transaction.on_commit()when the task reads rows written in the same request. - ▸Use
ImmediateBackendin development, andDummyBackendorImmediateBackendin tests. - ▸In production, install a backend that comes with a worker, run that worker as its own process, and clean up old results.
- ▸Check the backend's feature flags before relying on
run_after, priorities orget_result(). - ▸Use cron or your platform's scheduler for repeating jobs.
- ▸Keep Celery where you need retries, schedules, workflows or high throughput.
Sources
- ▸Django Software Foundation, Django 6.0 released (3 December 2025). djangoproject.com/weblog/2025/dec/03/django-60-released
- ▸Jake Howard, DEP 0014: Background workers (accepted, final). github.com/django/deps
- ▸Django 6.1 documentation, Django's Tasks framework. docs.djangoproject.com/en/6.1/topics/tasks
- ▸Django 6.1 documentation, Tasks (API reference). docs.djangoproject.com/en/6.1/ref/tasks
- ▸Django 6.1 documentation, Settings: TASKS. docs.djangoproject.com/en/6.1/ref/settings/#tasks
- ▸Django 6.1 documentation, Signals: Tasks signals. docs.djangoproject.com/en/6.1/ref/signals/#tasks-signals
- ▸Django 6.0 release notes: Background Tasks. docs.djangoproject.com/en/6.1/releases/6.0/#background-tasks
- ▸Django 6.1 release notes: Tasks (5 August 2026). docs.djangoproject.com/en/6.1/releases/6.1/#tasks
- ▸Django Software Foundation, Community Ecosystem: Background Tasks. djangoproject.com/community/ecosystem/#tasks
- ▸django-tasks-db 0.13.0, django-tasks-rq, django-tasks 0.12.0 and django-tasks-celery 0.1.1 (PyPI). pypi.org/project/django-tasks-db · django-tasks-rq · django-tasks · django-tasks-celery
- ▸Celery 5.7 documentation: Retrying, Periodic Tasks, Canvas, Backends and Brokers. docs.celeryq.dev
The diagrams use the official Django, Redis, Celery and PostgreSQL logos, which are trademarks of their respective owners. Not affiliated with the Django Software Foundation.