Durable Workflows: What a Celery Chain Survives, How Temporal Replays From History, and What Prefect Promises Instead
A durable run outlives the worker that started it. A six-step Celery chain killed at step 4 never finished with early acks (waited 203 s) and resumed at step 4 with acks_late (90 s later). Temporal replays the code and reads finished steps from history; Prefect records states and reruns from the top, leaning on saved results. Stay on Celery until you can name why not.
What you will learn
- Name the three kinds of job that strain a task queue
- Show what a Celery chain does when its worker is killed, with and without acks_late
- Explain Temporal's replay, its determinism rule and signals for human waits
- Compare Temporal's and Prefect's recovery, and decide when to leave Celery
Before you start
- Safe to run twice
- Celery pipelines with chain, group and chord
A durable workflow is a job that has to outlive the worker that started it. Temporal and Prefect are the two tools here, and they don't make the same promise.
You're playing a game that saves after each level. At level four it crashes. With no save you're back at the beginning; with a save you carry on. In this world, the save file is the run's recorded history. A durable run writes its own save file, so a crash costs one step, not the whole game.
Three jobs that strain a queue
- A run that goes on for days.
- A run that waits for a human, maybe for a week.
- A run that must resume in the same place with the same values.
Why not a countdown of three days? Celery's docs advise against it: it sits in the worker's memory, and on Redis it comes back again once it passes the visibility timeout. You can build all of this on Celery. The question is how much of it you want to write.
Killed at step 4: test Celery first
app.conf.update(task_acks_late=os.environ['ACKS'] == 'late', worker_prefetch_multiplier=1,
broker_transport_options={'visibility_timeout': 15})
@app.task(name='step')
def step(prev, n):
with open(LOG, 'a') as f:
f.write(f'{n} {os.environ["WORKER"]} {time.time():.1f}\n')
time.sleep(10 if n == 4 and os.environ['WORKER'] == 'worker-a' else 1)
return n
A six-step chain, once with the default early ack and once with acks_late, both killed with kill -9 on step 4 (Celery 5.5):
With the default, the ticket was acknowledged at the start, so the new worker got nothing; after more than three minutes, steps 5 and 6 still hadn't run. With acks_late, step 4 ran again about 90 seconds later on worker B, then 5 and 6 finished. It didn't restart from step 1, because the ticket for step 4 carries the rest of the chain. So a chain can survive a crash. What it lacks is a record of the whole run that the code can come back to. (Why the copy comes back is in safe to run twice.)
Temporal: same crash, replayed from history
From the lecture's slide, the workflow starts like this (trimmed):
@workflow.defn
class SubtitleJob:
@workflow.run
async def run(self, pid):
...
Each line in the workflow runs one step, and as steps finish Temporal writes them into an event history. Kill worker A during burn_in, and the history is safe on the Temporal Service. Worker B starts the code again from the top, reads the three finished results from the history (finished steps redone: zero), and reaches burn_in, which never finished, so that step runs again. That's replay: the code runs again, but the finished work comes out of the history.
What replay asks of you
- Workflow code must make the same calls in the same order every time. A branch on
datetime.nowcan take a different path on replay and you get a non-deterministic error; Temporal gives youworkflow.nowandworkflow.randominstead. - The real work goes into activities (
workflow.execute_activity), and those can use any library. - It's one more system to run: the Temporal Service plus your own workers.
- The step that crashed still runs twice, so activities still need their idempotency guard.
Waiting for a human
@workflow.run
async def run(self, pid):
await step(draft, pid)
await workflow.wait_condition(
lambda: self.approved)
await step(publish, pid)
@workflow.signal
...
The code writes a draft and reaches wait_condition. It waits a day, or three. If the workers restart meanwhile, replay comes back to this same line. A person clicks approve, which is a signal that sets approved to true, and the run carries on with publish. Timers work the same way: one that fires while the workers are down resolves when they're back.
Prefect: flows, tasks and retries
@task(retries=3, persist_result=True)
def transcribe(pid): ...
@flow(retries=2)
def subtitle_job(pid):
fetch_audio(pid)
transcribe(pid)
A different kind of tool. A flow and its tasks are plain Python functions with decorators, and Prefect records the state of each. Transcribe raises, and retries=3 takes it through retrying to completed; the flow moves on. Around that you get schedules, deployments and automations. There are no replay rules on your code. Prefect's job is to orchestrate: run it, retry it, watch it.
When a Prefect run crashes
- Your code raises: retries come first, and it's failed only when they run out.
- The process dies: that's crashed, a final state, so retries don't fire.
- Killed outright: it can sit as running until missed heartbeats get it marked crashed.
The next move is yours: prefect flow-run retry or an automation. Then the flow function runs again from the top, and tasks with a saved result simply return it. It's recoverable, but it's not replay: a task with no saved result runs again. For scheduled batch pipelines, see orchestrating ML pipelines with Airflow.
Not the same kind of durable
| Temporal | Prefect | |
|---|---|---|
| After a crash | A worker carries on by itself | You arrange the rerun |
| What's kept | Every step's result | States, plus the results you persist |
| Your code | Workflow code must be deterministic | Plain Python |
| A long wait | wait_condition: same line after any restart | Suspend: the process exits until resumed |
One resumes your code. The other runs it again and leans on saved results. Agent runs with checkpoints are a close cousin, in durable agent runs.
Quick recap
- A Celery chain's ticket carries what's left, so
acks_lateresumes at the killed step. - Temporal replays your code from its history; keep workflow code deterministic.
- Prefect orchestrates; a crash needs a rerun, and persisted results are skipped.
Try it yourself
Write one sentence: the thing Celery cannot do for your subtitle pipeline. No sentence? Then stay on Celery.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
Python Virtual Environments: One Project, One Toolbox
Why every Python project gets its own virtual environment: two projects that need different versions of requests, python -m venv .venv, activation, pip install and the PyCharm setting that activates it for you.
Git and GitHub Fundamentals: Commits, Branches, Push and Pull
The Git you use every day, on a tiny hello-ml project: commits as save points, the staging area, a branch merged with a fast-forward, then push, clone, pull and pull requests with a teammate.
Testing a FastAPI App with pytest: Three Small Tests
A tiny FastAPI app with a Hello World route and a name route that refuses numbers, three pytest tests that check it, and what happens when the validation is deleted by mistake.
Config and Logging Instead of Hard-Coded Values in ML Training
Take the hard-coded values out of a car price training script: one config.toml read with tomllib, logging with levels and a run id on every line, and secrets read from the environment. Same RMSE, 2195, before and after.
