Celery production settings: acks_late, time limits and queue routing

Backend Live Coding November 13, 2026 python

Separate queues and workers for heavy tasks (video), for integrations and for fast tasks (emails), so one doesn't block the others.

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# ======================================================================
# Q: Which Celery settings do you always change in production?
#
# Separate queues and workers for heavy tasks (video), for integrations and for
# fast tasks (emails), so one doesn't block the others. Celery beat runs on a
# single instance, otherwise periodic tasks run twice.
# ======================================================================

CELERY_TASK_ACKS_LATE = True               # ack after execution
CELERY_TASK_REJECT_ON_WORKER_LOST = True
CELERY_WORKER_PREFETCH_MULTIPLIER = 1       # fair distribution for large tasks
CELERY_TASK_TIME_LIMIT = 300                # hard kill
CELERY_TASK_SOFT_TIME_LIMIT = 270           # SoftTimeLimitExceeded for cleanup
CELERY_WORKER_MAX_TASKS_PER_CHILD = 1000    # safety net for memory leaks
CELERY_TASK_ROUTES = {
    'media.tasks.transcode': {'queue': 'heavy'},
    'integrations.tasks.*': {'queue': 'integrations'},
}
# Redis broker: visibility_timeout > the slowest task, otherwise double execution
CELERY_BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 3600}