Python Celery explained for beginners to Professionals(Part-2) — Applications (WHY, WHEN and WHERE) of Python Celery
Hi,
In my previous post, I have introduced you to Celery and a little hands-on on it. If you have not read my previous post, please read.
In this post, We will discuss on Why, When and Where we have to use the Python Celery in different Software or Application systems.
WHY, WHEN and WHERE
Celery can be used if
a) You want to run some tasks in the background.
b) You want to offload some tasks(long running or time taking or CPU consuming) to Celery workers running on different machines to improve response of main Application Server.
c) You want to schedule the tasks at regular intervals.
d) You want to parallelize the tasks or scale your Software or Application systems.
In my experience when above conditions are met, you can use Python Celery in different domains such as E-Commerce, Health Care, Banking, etc.
a) You want to run some tasks in the background.
Assume you have an E-commerce application. When a user orders, your application needs to send text messages and emails on order updates like order placement, payments, shipments, etc.
Assume you have a Django/Flask application, when user orders, you shouldn’t send emails/text messages in the same order django/flask http request. If you do so, it simply delays response for user because email server/text message server may not respond quickly.
Here you need to create/define tasks for sending email/text messages. You invoke these tasks accordingly. Celery workers will work on these tasks in the background, but the response to user will be quick.
b) You want to offload some tasks(long running or time taking or CPU consuming) to Celery workers running on different machines to improve response of main Application Server.
Assume you have a Data Analysis application. When a user requested some complex data analysis calculation on data, it has come to your Django/Flask application but you don’t want to run this calculation on same machine where your Django/Flask application is running because the calculation takes a lot of time and also eats the CPU of this machine which results in poor response of Django/Flask application. Your Django/Flask application application will not be able to respond to further requests by different users. So what you do here?
Simple, you create/define a task for complex data analysis calculation in Python Celery and run celery worker on different machine and Django/Flask application on different machine.
Now When a user requested some complex data analysis calculation on data, it has come to your Django/Flask application but you invoked respective Celery tasks. As Celery worker is running on different machine, calculation happens on different machine.
c) You want to schedule the tasks at regular intervals.
Assume you have an E-commerce application. You want to send product recommendations to users emails daily.
You can create/define a Celery task and schedule it with Celery beat.
d) You want to parallelize the tasks or scale your Software or Application systems.
Assume you have celery tasks but you have only one worker which is doing all the tasks. Your application is not able to meet the demands of user needs.
You want to run the multiple tasks at same time to improve the performance of the application.
Answer is you increase the number of celery workers on multiple machines.
We will get into more in our next story. If you like the story, please follow me and provide suggestions.






