Essential Apache Airflow Interview Questions & Answers (Explained Through Real-World Stories) – Part 2
6. What is the Airflow UI used for?
Imagine you've scheduled hundreds of workflows every day.
How do you know:
- Which DAG is currently running?
- Which task failed?
- How long did a task take?
- Why did it fail?
Instead of checking log files manually, Apache Airflow provides a powerful Web UI.
The Airflow UI helps you monitor, troubleshoot, and manage your workflows from a web browser.
Some useful views include:
| View | Purpose |
|---|---|
| DAGs View | Displays all available DAGs |
| Graph View | Shows task dependencies visually |
| Grid View | Displays task status across DAG runs |
| Code View | Shows the DAG source code |
| Logs | Displays execution logs for each task |
Real-World Example
Suppose your ETL pipeline looks like this:
Extract Data
↓
Transform Data
↓
Load Warehouse
↓
Generate Report
If Transform Data fails, the UI highlights the failed task, allowing you to inspect its logs without searching through server files.
7. How do you create your first DAG in Apache Airflow?
A DAG is simply a Python file that defines your workflow.
Example:
from airflow import DAG
from airflow.operators.empty import EmptyOperator
from datetime import datetime
with DAG(
dag_id="first_dag",
start_date=datetime(2025, 1, 1),
schedule="@daily",
catchup=False
) as dag:
start = EmptyOperator(task_id="start")
Explanation
dag_iduniquely identifies the DAG.start_datetells Airflow when scheduling begins.scheduledefines how often the DAG runs.catchup=Falseprevents Airflow from running historical schedules.
Once saved inside the dags/ folder, Airflow automatically discovers the DAG.
8. What are Operators in Apache Airflow?
Operators define what each task should do.
Think of an Operator as a worker assigned a specific responsibility.
For example, in an ETL workflow:
Download File
↓
Run Python Script
↓
Execute SQL Query
↓
Send Email
Each step is performed by a different Operator.
Some commonly used Operators are:
| Operator | Purpose |
|---|---|
| PythonOperator | Executes Python functions |
| BashOperator | Runs shell commands |
| EmptyOperator | Placeholder task |
| EmailOperator | Sends emails |
| HttpOperator | Calls REST APIs |
Example
from airflow.operators.bash import BashOperator
task = BashOperator(
task_id="list_files",
bash_command="ls -l"
)
This task executes the Linux command ls -l.
9. How do you define task dependencies in Airflow?
Many workflows require tasks to execute in a specific order.
For example:
Receive File
↓
Validate Data
↓
Transform Data
↓
Load Database
You don't want Load Database to start before Validate Data finishes.
Airflow lets you define dependencies using the >> and << operators.
Example
extract >> transform >> load
This means:
extractruns first.transformstarts only afterextractsucceeds.loadruns aftertransform.
You can also define parallel tasks.
start >> [task1, task2, task3]
Here, all three tasks run simultaneously after start completes.
10. How does scheduling work in Apache Airflow?
Scheduling determines when a DAG should execute.
Airflow supports:
- Fixed schedules
- Cron expressions
- Presets
- Manual triggers
- Dataset-based scheduling (Airflow 2.4+)
Common Schedule Examples
| Schedule | Meaning |
|---|---|
@once | Run only once |
@hourly | Every hour |
@daily | Once every day |
@weekly | Every week |
@monthly | Every month |
You can also use Cron expressions.
Example:
schedule="0 8 * * *"
This runs the DAG every day at 8:00 AM.
Another example:
schedule="*/15 * * * *"
This executes the DAG every 15 minutes.
Real-World Example
A retail company refreshes sales dashboards every morning at 6 AM.
Instead of manually starting the workflow every day, Airflow automatically triggers the DAG using a scheduled interval.
Summary
| Question | Topic |
|---|---|
| 6 | Airflow UI |
| 7 | Creating Your First DAG |
| 8 | Operators |
| 9 | Task Dependencies |
| 10 | Scheduling & Cron Expressions |
Interview Tip
A common interview question is:
"What is the difference between scheduling a DAG and manually triggering a DAG?"
A simple answer:
- Scheduling runs the DAG automatically according to a predefined schedule.
- Manual triggering starts the DAG on demand, regardless of its schedule.
Both methods create a DAG run, but the trigger mechanism is different.