The Definitive Guide to Celery and Django

  • Updated April 5th, 2021
  • v1.0.0
Michael Yin Michael Yin

In this course, you will learn how to add Celery to a Django application, allowing you to handle asynchronous tasks, which is vital to smooth user experiences. With this powerful combo, you will be able to do things like:

  • Running machine learning models
  • Sending bulk emails
  • Processing images or PDFs
  • Generating exports of user data
  • Performing backups

These functions are increasingly common in modern web applications, but with Celery they are easy to implement. Because so many of these activities may be critical to the operation of your application, this course will walk you through configuring, testing, deployment, and monitoring of Celery tasks. With this setup, you can be assured that your tasks are firing and working as expected, outside the HTTP request/response flow.

Django + Celery

What will you learn?

Select a Part

In this first part, you'll learn how to configure Celery to work with Django and Docker in order to process tasks in the background asynchronously. We'll then look at how to retry failed tasks, debug tasks, and ensure tasks work with Django database transactions correctly. Finally, we'll add WebSocket support to Django with Django Channels.

Learning Objectives

  1. Containerize Django, Celery, and Redis with Docker
  2. Ensure Celery tasks execute correctly with validation and debugging
  3. Create and manage Celery tasks
  4. Configure Django Channels to add WebSocket support to a Django application

In part 2, we'll dive into testing with the standard Django testing framework and pytest. We'll also look at a Test-Driven Development (TDD) workflow. You'll then deploy the application to DigitalOcean and learn how to properly monitor Celery tasks with Flower, Container Advisor, and Prometheus. Finally, we'll look at some Celery best practices and tips for performance tuning.

Learning Objectives

  1. Setup logging with Papertrail
  2. Practice Test-Driven Development
  3. Deploy Django and Celery to DigitalOcean
  4. Configure monitoring

What do you need to know?

This course is targeted at advanced-beginners -- someone with at least 6 months of web development experience. Before beginning, you should have some familiarity with the following topics:

Meet the Author

Michael Yin

Michael Yin

Michael Yin is a full-stack developer from China with experience in Django, Python, and Javascript. He also loves writing blog posts to teach people programming.

What developers are saying

If you want to learn how to create a modern app from frontend to backend to live deployment using software engineering best practices from start to finish, TestDriven.io will get you there.

As someone who's already a senior developer but moving into a different development space, the TestDriven.io courses are exactly what I need. I've had a hard time finding something advanced enough to propel me forward into this tricky, but exciting world of Python.

Michael's courses have enabled me to go from idea to a fully formed application with real users using them every day. His writing is terrific and the material strikes a good balance between being practical and theoretical as well as showing you some gotchas. Well worth every single dollar. I just wish there were more of them!

The TestDriven.io courses are worth 10 times what I paid for them.

Frequently Asked Questions

What tools and technologies are used in this course?

This course covers a variety of technologies and services:

Core

  • Python
  • Django
  • Celery
  • Django Channels
  • Flower
  • Docker
  • Postgres
  • Redis
  • RabbitMQ
  • Gunicorn
  • Uvicorn

Testing and Monitoring

  • pytest
  • factory_boy
  • Coverage.py
  • Container Advisor
  • Prometheus
  • Papertrail
  • DigitalOcean

Services

  • Papertrail
  • DigitalOcean
What can I learn to build with Django and Celery?

Celery is perfect for managing background and periodic tasks. In Django applications, it's commonly used for:

  • Performing long running tasks, like processing image uploads such as cropping, resizing, compressing, or building various thumbnails.
  • Similarly, generating PDFs of large datasets, perhaps as part of an export.
  • Sending bulk emails to users, perhaps as part of a mailing list, email-based game, or facilitating redundancy in forum software.
  • Performing tasks on a schedule, such as a regular backups, generating activity digests, or scraping web content during low traffic periods.

Celery is a must-have for many Django web applications because of these common use cases.

What support does TestDriven.io offer?

Since the courses mimic real-world development, support is provided via Stack Overflow. Helpful users, including the developers of the courses, read and respond to messages on Stack Overflow. If you get stuck and you can't find an answer via Stack Overflow, feel free to reach out via email directly. Just be sure to detail what you've tried. For more, review Support and Consulting.

How long does it take to complete the course?

It's dependent on your current skill level. On average, it takes approximately 12 hours to complete.