4. Retry the Flaky API, Not the Bad Data
Difficulty: Medium · Topic: Retries & failures
The DAG fx_rates runs @daily from 2026-01-01 (no catchup) with three BashOperator tasks in a chain:
fetch_rates:fetch_rates --date {{ ds }}. The rates API times out now and then: a failed attempt should be retried up to 3 times, 2 minutes apart.validate_rates:validate_rates --date {{ ds }}. When validation fails the data is wrong, and running it again gives the same answer: it must fail at once, without retrying.publish_rates:publish_rates --date {{ ds }}, with the same retry policy asfetch_rates.
Put the shared retry policy in default_args. The tests make some attempts fail and check how many tries each task took and when each one finished.
Your DAG file is run in a simulation of the Airflow 3 scheduler against 5 scenarios, including hidden ones.
Sample scenario: The API times out twice
Deployed 2026-01-10 00:30 UTC, read at 2026-01-10 02:00 UTC.
Expected runs
- Run at 2026-01-10 00:00 UTC: success. fetch_rates success, validate_rates success, publish_rates success
Hints
Hint 1
default_args={"retries": 3, "retry_delay": timedelta(minutes=2)} applies to every task in the DAG.Hint 2
An argument passed to the operator wins overdefault_args: retries=0 on one task turns retrying off for it.Hint 3
retries=3 means up to 4 tries in all. Without retry_delay, Airflow waits 5 minutes between tries.Learn the concepts
- Retries, timeouts and callbacks · 5 min read. Which failures to retry, how retry_delay and backoff space them, timeouts, and failing fast.