What if your system could fix missed work all by itself, without you lifting a finger?
Why Catchup and backfill behavior in Apache Airflow? - Purpose & Use Cases
Imagine you have a daily task to process sales data, but your system was down for three days. You now need to run those missed days manually, one by one, to catch up.
Manually running each missed task is slow and error-prone. You might forget a day or run tasks in the wrong order, causing inconsistent data and wasted time.
Catchup and backfill behavior in Airflow automatically detects missed runs and executes them in the correct order, ensuring no data is lost and your workflow stays consistent.
airflow dags trigger process_sales --exec-date 2024-04-01 airflow dags trigger process_sales --exec-date 2024-04-02 airflow dags trigger process_sales --exec-date 2024-04-03
airflow dags backfill process_sales -s 2024-04-01 -e 2024-04-03
You can trust your workflows to automatically fill gaps and keep data accurate without manual intervention.
A marketing team missed running their daily campaign report for a weekend. Using backfill, Airflow runs those reports for the missed days automatically, so the team gets complete data on Monday morning.
Manual reruns are slow and risky.
Catchup and backfill automate missed task runs.
This keeps workflows reliable and data complete.
Practice
catchup=True do in an Airflow DAG?Solution
Step 1: Understand catchup parameter
Thecatchupparameter controls whether Airflow runs missed DAG runs automatically.Step 2: Effect of catchup=True
Whencatchup=True, Airflow schedules and runs all DAG runs that were missed since the last run.Final Answer:
It runs all missed DAG runs automatically to catch up. -> Option DQuick Check:
catchup=True means run missed DAG runs [OK]
- Confusing catchup with manual backfill
- Thinking catchup disables scheduling
- Assuming catchup deletes runs
Solution
Step 1: Identify catchup parameter usage
Thecatchupparameter is used to enable or disable catchup behavior in DAGs.Step 2: Disable catchup by setting catchup=False
Settingcatchup=Falsedisables automatic running of missed DAG runs.Final Answer:
dag = DAG('my_dag', catchup=False) -> Option CQuick Check:
Disable catchup with catchup=False [OK]
- Using backfill parameter instead of catchup
- Setting schedule_interval to None disables scheduling, not catchup
- Setting catchup=True enables, not disables
start_date='2024-04-01', schedule_interval='@daily', and catchup=True, if the DAG was paused and resumed on 2024-04-05, which DAG runs will Airflow execute immediately after resuming?Solution
Step 1: Understand catchup=True behavior
Withcatchup=True, Airflow runs all missed DAG runs fromstart_dateto current date.Step 2: Identify missed runs
The DAG was paused from 2024-04-01 to 2024-04-04, so runs for 2024-04-01, 02, 03, 04 were missed. On resuming 2024-04-05, Airflow runs all missed plus current.Final Answer:
Runs for 2024-04-01 to 2024-04-05 -> Option AQuick Check:
Catchup runs all missed dates including current [OK]
- Thinking only current date runs after resume
- Ignoring runs before resume date
- Assuming no runs run automatically after pause
Solution
Step 1: Identify manual run command for date range
Theairflow dags backfillcommand runs DAG runs manually for a specified date range.Step 2: Confirm correct syntax
Using-sand-eflags withbackfillspecifies start and end dates for manual runs.Final Answer:
airflow dags backfill -s 2024-03-01 -e 2024-03-05 my_dag -> Option AQuick Check:
Backfill runs DAG manually for date range [OK]
- Using trigger command with date range flags (not supported)
- Trying to use catchup command (does not exist)
- Using dags run with invalid date range syntax
catchup=False and a start_date set to 2024-01-01. You want to run all DAG runs from 2024-01-01 to 2024-01-10 manually. What is the best approach to achieve this without enabling catchup?Solution
Step 1: Understand catchup=False effect
Withcatchup=False, Airflow skips running missed DAG runs automatically.Step 2: Use backfill to run missed DAG runs manually
To run missed DAG runs without enabling catchup, use thebackfillcommand specifying the date range.Final Answer:
Use the backfill command for the date range 2024-01-01 to 2024-01-10. -> Option BQuick Check:
Backfill runs missed DAG runs manually without catchup [OK]
- Enabling catchup when not desired
- Assuming one trigger runs all missed dates
- Changing start_date to skip missed runs
Ready to prove it?
Pass the test and this pattern moves unknown
