Asynchronous solutions for Django
The rest of this chapter will cover the following popular asynchronous systems used with Django, with somewhat different use cases. They are as listed as follows:
- Celery: Worker threads-based model for handling computation outside the Django process
- asyncio: Python built-in module for concurrently executing multiple tasks within the same thread
- Django Channels: Real-time message queue-like architecture to manage I/O events such as WebSockets
Let's first understand the most popular and robust solution for running tasks asynchronously: Celery.
Working with Celery
Celery is a feature-rich asynchronous task queue manager. Here, a task refers to a callable that, when executed, will perform the activity asynchronously. Celery is used in production by several well-known organizations including Instagram and Mozilla, for handling millions of tasks a day.
While installing Celery, you will need to pick and choose various components such as a broker and result store. If you...