Skip to main content

Command Palette

Search for a command to run...

Introduction to Celery in Django?

Celery, keeps you healthy if you include it in your diet.

Published
2 min read
Introduction to Celery in Django?
G

Experienced Full Stack Software Engineer with 4+ Years of experience, proficient in Django and React, with expertise in Python, JavaScript and Typescript, also an author of Dev.Junction Blogs & YouTube Channel, expert in Python/Django, Rest Framework, ReactJS/NextJS and TypeScript, currently based in Pune, India.

Note: If you are looking for a Full Stack Developer (Django+React), then connect with me on LinkedIn or contact me through my portfolio.

Introduction:

Celery is an asynchronous task queue in Django, basically used for queuing time-consuming tasks. Let me give you a real world use case of Celery.

Analogy:

Let’s say you have an application where you want to send a Welcome Email to the user after Sign Up, if you perform this operation synchronously with Django, it will be going to hold the HTTP request execution until the email is sent.

Now to solve this problem, we can transfer this task burden to a task queue such as Celery, so whenever a user Sign Up in your application, your HTTP request will continue the process, and then it will pass the task to Celery instance, which is running in a different server (service).

Task Broker:

Now, Celery is not capable of executing those asynchronous task all by itself, because Celery is just a service running in your server.

Whenever a task comes to Celery, it stores the task with a unique ID inside a persistent storage called Task Broker.

Now, the job of this Task Broker is to assign a task ID to any message that comes, and then forward it to Celery for further processing.

We do not use relation databases because these are slow, on the other hand task brokers are fast, reliable, concurrency enabled.

Two very popular task brokers are RabbitMQ and Redis.

Installation:

Installing Celery in a Django project is pretty easy:

pip install celery

That’s it for today, in the next blog, we will learn how to use Celery in a Django project and how to execute it asynchronously.

For more such crispy blogs daily, follow Dev.Junction, subscribe to our newsletter and get notified.

Learn Celery

Part 3 of 3

In this series of Blogs, we will be learning and implementing Celery from the ground up in Django with RabbitMQ.

Start from the beginning

How to create an asynchronous task in Celery with Django?

First, solve a problem, then again solve 100 more problems.