Celery chain, group and chord explained with examples

Backend Live Coding November 13, 2026 python

A chord needs a result backend and is sensitive if one part fails.

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# ======================================================================
# Q: What are chain, group and chord? Give an example.
#
# A chord needs a result backend and is sensitive if one part fails. For very
# large fan-outs (e.g. 250,000 screens) I don't create one task per screen but
# batches (e.g. 500 ids per task) so the broker doesn't fill up.
# ======================================================================

from celery import chain, group, chord

# chain: one after the other, the result is passed to the next
chain(download_media.s(media_id), transcode.s(), make_thumbnail.s())()

# group: in parallel
group(push_update.s(screen_id) for screen_id in screen_ids)()

# chord: in parallel, then a callback when all are done
chord(render_report_part.s(i) for i in range(10))(merge_report.s(report_id))