Sending email, processing images or calling slow APIs inside a web request makes users wait. Celery moves that work to background workers, with Redis as the message broker.

1. Install Redis and Celery

sudo apt install redis-server -y
sudo systemctl enable --now redis-server
pip install celery redis

2. Define a task

from celery import Celery
app = Celery("tasks", broker="redis://localhost:6379/0")

@app.task
def send_report(user_id):
    # slow work here
    ...

Call it with send_report.delay(user_id) and the web request returns immediately.

3. Run the worker under systemd

ExecStart=/var/www/app/venv/bin/celery -A tasks worker --loglevel=info

Add Restart=always so the worker recovers from crashes.

Scaling

Run more worker processes (or more VPSes) as your job volume grows, and add Celery Beat for scheduled tasks. Redis and Celery run comfortably alongside your app on a single VPS with enough RAM.