Retries, timeouts and callbacks
Some failures fix themselves: a timeout, a busy database, a rate limit. Retries handle those without waking anyone up; other failures need a person. This lesson shows how to configure retries, back-off and timeouts, and how to tell which failures to retry.
Pipelines in production · Airflow · Silver · Failures, lesson 1 of 2
On this page
Read first: Operators and TaskFlow (skip if you know it)
In plain words first
If a phone call does not connect, you try again a minute later, then five minutes later. If the number does not exist, ringing it a hundred times will not help.
Retries are for the first kind of failure. A good pipeline retries temporary errors, waits longer each time, and fails quickly on the second kind.
Retry what can recover
A retry helps when the next attempt can succeed: a timeout, a dropped connection, a lock held by another job, a rate limit. It does not help when the input is wrong or the code has a bug: the attempt fails the same way, and the alert just comes later. Decide per tasktask: One step of a DAG, such as running a query or calling an API. Each run of a task for one date is a task instance. Learn more →.
retries and retry_delay
retries=3 means up to four attempts. After a failed attempt with retries left, the task instancetask instance: One run of one task for one DAG run, with its own state (queued, running, success, failed) and its own log. Learn more → goes to up_for_retry and starts again retry_delay later (5 minutes by default). Put the shared policy in default_args and override it on the tasks that differ:
import pendulum from datetime import timedelta from airflow.sdk import DAG from airflow.providers.standard.operators.bash import BashOperator with DAG( dag_id="payouts", schedule="@daily", start_date=pendulum.datetime(2026, 3, 1, tz="UTC"), default_args={"retries": 3, "retry_delay": timedelta(minutes=10)}, ): download = BashOperator(task_id="download_statement", bash_command="fetch_statement --day {{ ds }}") check = BashOperator( task_id="check_totals", bash_command="check_totals --day {{ ds }}", retries=0, # a wrong total will not fix itself ) pay = BashOperator(task_id="pay_artists", bash_command="pay_artists --day {{ ds }}") download >> check >> pay
What the schedulerscheduler: The Airflow process that reads DAG files, creates runs when they are due, and queues the tasks whose upstream tasks are done. Learn more → does · deployed Mar 5, 00:30 UTC · grid as of Mar 6, 02:00 UTC · failing: download_statement in the 2026-03-05 run (try 1, 2); check_totals in the 2026-03-06 run · @daily (CronTriggerTimetable)
| task \ run | Mar 5 00:00 | Mar 6 00:00 |
|---|---|---|
| download_statement | 3 | |
| check_totals | ||
| pay_artists |
successfailedupstream failed· the bar on top is the run's state; a number is how many tries
On 5 March the download fails twice and succeeds on the third try, 10 minutes after each failure, and the run goes on. On 6 March check_totals fails once and stays failed; pay_artists never runs. Hover a cell in the grid to see its tries.
Backing off
retry_exponential_backoff=True doubles the wait after each failure (with some jitter so many tasks do not retry at the same instant), capped by max_retry_delay. Use it for APIs and services that fail under load: hammering them every five minutes keeps them down.
Timeouts
| Setting | Stops | Then |
|---|---|---|
execution_timeout=timedelta(hours=1) on a task | One attempt that runs longer than an hour | The attempt fails; retries still apply |
dagrun_timeout=timedelta(hours=6) on the DAGDAG: A pipeline in Airflow: a set of tasks and the order they run in, defined in a Python file and run on a schedule. Learn more → | A whole run still going after six hours | The run is marked failed |
Without an execution timeout, a job that hangs (a lock that never frees, a query that never returns) holds its workerworker: The process that actually runs a task instance, on whatever machine the executor sends it to. Learn more → slot forever and nothing alerts. Set one on every task that talks to another system, comfortably above its normal duration.
Failing fast, and hearing about it
- In Python code,
raise AirflowFailException("...")fails the task immediately, whateverretriessays. Use it when the code knows the problem is permanent. raise AirflowSkipException("...")marks the task skipped instead, for "nothing to do today".on_failure_callbackandon_retry_callbackrun a function (or a notifier, such as the Slack provider's) when a task fails or retries. Put them indefault_argsso every task alerts the same way.
Common mistakes
- Retrying validation or data-quality failures — Every attempt fails the same way; the alert is just later.
- No execution_timeout on tasks that call other systems — A hung call holds a worker slot forever.
- retries=3 assumed to mean three attempts — It is four: the first try plus three retries.
- Fixed short delays against a struggling API — Use exponential backoff and a max_retry_delay.
Key takeaways
- Retry transient failures; fail fast on permanent ones.
- retries=N means N+1 attempts; retry_delay defaults to 5 minutes.
- execution_timeout stops a hung attempt; dagrun_timeout a whole run.
- AirflowFailException skips the remaining retries; callbacks send alerts.
Interview prep
THE QUESTION
"How do you configure retries for a DAG that downloads from a flaky API and then validates the file?"
Avoid: "set retries=5 everywhere". Retries delay the alert for failures that will never recover, such as bad data or a bug.
Follow-ups · answer out loud, then open
Follow-up"What is the difference between execution_timeout and dagrun_timeout?"
Scenario"An API returns HTTP 429 (too many requests) during the nightly load. How do you configure the task?"
Trap"AirflowSkipException marks the task failed but keeps the run going."
Check yourself
3 questionsretries=3 and every attempt fails. How many attempts run?
Show the answer
4. The first try plus three retries.
Which exception fails a task without using its retries?
Show the answer
AirflowFailException. AirflowFailException marks it failed immediately.
What does execution_timeout stop?
Show the answer
One attempt of a task that runs too long. The attempt fails; remaining retries still apply.
Practise this
Problems that use this, graded on hidden tests
Keep going
Up next · Failures · lesson 2 of 2 · 5 min readTrigger rules and run state
When a task runs after its upstream tasks fail or skip, and how a run gets its final state.
Related lessons
Previous: Templates and idempotent reruns
Primary sources: Tasks: retries and timeouts · Callbacks