SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
  • Batch vs Stream Processing
  • Change Data Capture (CDC)
  • MapReduce
  • ETL Pipelines
  • Data Lakes
  • Data Warehousing
  • Data Lakehouse
  • Lambda Architecture
  • Kappa Architecture
  • Streaming Engines
  • Spark and Hadoop
  • Workflow Orchestration (Airflow)
  • Parquet and Columnar File Formats
  • Data Governance and Feature Stores
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Advanced Data Topics/Big Data Processing

Workflow Orchestration (Airflow)

Describe a pipeline as tasks and dependencies, and let a scheduler run, retry and monitor it.

⏱ 13 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A workflow orchestrator such as Apache Airflow does not process data. It decides what runs, when, and in what order, and it retries and reports when something fails. You describe a pipeline as a DAG: tasks plus the arrows between them.

  • The work (a Spark job, a SQL query, a script) runs somewhere else. Airflow starts it and watches it.
  • The schedule says when each run happens (for example every day at 02:00).
  • The rules say what to do on failure: retry, alert, skip, or stop the downstream tasks.

02Concept: What is it?

A cron job can start a script at 2 am. But real pipelines have many steps: wait for a file, extract, clean, load, build a report, tell the team. Some steps must wait for others. Some can run side by side. Some fail and need a retry. Doing that with a pile of cron lines and shell scripts gets fragile fast. An orchestrator gives it structure.

In Airflow you write a DAG (Directed Acyclic Graph) in Python. A DAG is a set of tasks and the dependencies between them. "Directed" means each arrow has a direction. "Acyclic" means there are no loops, so there is always a clear order to run in.

The parts of Airflow
📄DAG filesPython code
→↓read
⏱️Schedulerdecides what is due
→↓queue tasks
⚙️Executor and workersrun the tasks
🗃️Metadata databasestate of every run and task
↔
🖥️Web UI and APIwatch, clear, trigger
The scheduler reads DAG files, creates runs, and hands tasks to workers. The state of everything is kept in the metadata database.
🧠Orchestrate, do not compute
Airflow should trigger the Spark job or the warehouse query, not do the heavy data processing inside its own workers. It is the conductor, not the orchestra.

03Real-Life Example

🍵The Kitchen Pass in a Restaurant
In a busy kitchen the head chef does not chop every vegetable. They call the orders: "the sauce goes on after the pasta is boiled, the salad can start now, and table 4 needs the dessert last." If a pan burns, the chef says "make it again", and tells the waiter if the order will be late. The cooks do the work. The chef keeps the order, timing and retries.
Kitchen
Airflow
Head chef calling orders
Scheduler
A recipe with steps and an order
A DAG
One step (chop, boil, plate)
A task
Cooks doing the work
Workers and the systems they call (Spark, SQL)
Waiting for the delivery to arrive
A sensor
“Make it again”
A retry
Telling the waiter about a delay
An alert or SLA miss

04Why Do We Need It?

🧭Order and dependencies
Step B starts only when step A succeeded. Independent steps run side by side.
🔁Retries and recovery
A flaky step retries on its own. After a fix you re-run only what failed.
👀One place to look
The UI shows every run, every task and every log, so you do not hunt through servers.
📅Schedules and backfills
Run daily, hourly or on a trigger, and replay past days after fixing a bug.
🔔Alerts
Send a message when a task fails or a pipeline is late.
📝Pipelines as code
DAGs live in Git, are reviewed, tested and versioned like any other code.
An orchestrator turns a pile of scripts into a pipeline you can see, retry, replay and trust.

05Where Do We Use It?

🔄ETL and ELT
Extract, transform and load jobs that run every night or every hour.
🤖Machine learning
Build features, train, check quality and publish a model, in order.
📊Reports and dashboards
Refresh tables after the data has landed, then send the daily report.
🧹Data maintenance
Compact files, expire old data, run quality checks and backups.
🔌Cross-system flows
Start a Spark job, wait for it, run a warehouse query, then call an API.
🚦Release and ops tasks
Scheduled maintenance, report generation and housekeeping.

06Types / Parts / How It Works

Building blocks of a DAG

PieceWhat it isExample
TaskOne unit of work in the DAGRun a SQL file
OperatorA template for a type of taskSparkSubmit, BigQuery, Bash, Python
SensorA task that waits until something is trueWait for a file in object storage
HookA reusable connection to an outside systemPostgres or S3 connection
XComA tiny message passed between tasksA file path or a row count. Never a big dataset
PoolA cap on how many tasks may use a resource at onceAt most 5 tasks against one database
Trigger ruleWhen a task may run, based on upstream resultsall_success (the default), all_done, one_failed

Task states you will see

Life of a task
⌛scheduled
→↓
🏃running
→↓ok
✅success
🏃running
→↓error, retries left
🔁up_for_retry
→↓no retries left
❌failed
→↓downstream
🟠upstream_failed
Failed tasks make everything after them upstream_failed, so bad data does not flow on.

Time in Airflow: the part that confuses everyone

A daily DAG run covers a data interval, for example "all of Monday". The run starts after that interval ends (early Tuesday), because only then is Monday's data complete. The logical date is the start of the interval, so a run that executes on Tuesday has a logical date of Monday. Use it in your queries instead of "now", so a re-run of Monday's run still reads Monday's data.

Why a daily run happens after the day it covers
📆Mondaydata interval: Mon 00:00 to Tue 00:00
→↓interval ends
🚀Run starts Tuesdaylogical date = Monday
→↓reads Monday only
🗂️Partition date=Monoverwritten each time
Data covered When it runs
Monday's data is only complete once Monday has ended.
VisualizerRun a DAG and watch failures spreadClick a task, then make it fail. Set the retries and press Next step. Failed tasks turn the tasks after them to upstream_failed, while the parallel branch carries on. Try the short-circuit check too.
How should “clean” behave? (click a task to pick it)
The profile task is…
extractno statuscleanno status✗loadno statusprofileno statusreportno status
no statusrunningsuccessup for retryfailedupstream failedskipped
Scheduler step
0 / 7
DAG run
running
in progress
Retries
1
per task
A DAG run is created. Every task starts with no state, waiting for its upstream tasks. Press Next to let the scheduler take one step.

A simplified model: one scheduler step moves every ready task one state forward, and retries have no delay. Colours follow the Airflow UI. A real scheduler also respects pools, concurrency limits and trigger rules (here every task uses the default “all upstream succeeded”).

07How to Use It / Steps / Implementation

Designing a pipeline that behaves

  1. 1
    Draw the steps first
    List the tasks and which need which. Keep each task small and focused on one job.
  2. 2
    Make every task idempotent
    Running it twice for the same interval gives the same result. Write to a partition by date and overwrite it, do not append blindly.
  3. 3
    Use the logical date, not now
    Pass the interval to queries so re-runs and backfills read the right data.
  4. 4
    Let other systems do the heavy work
    Trigger Spark, SQL or a container, and wait for it. Do not process big data inside Airflow workers.
  5. 5
    Pass small things through XCom
    A path, a count or an ID. Put the data itself in storage.
  6. 6
    Set retries and timeouts
    A few retries with a delay catch temporary problems. A timeout stops a stuck task from running forever.
  7. 7
    Add alerts and checks
    Alert on failure or lateness, and add data quality checks as tasks so bad data stops the flow.
  8. 8
    Test the DAG file
    Check that it imports quickly and has no cycles. Keep slow code out of the top of the file.
💡What a DAG looks like in code
extract >> clean >> load and extract >> profile >> report. The >> arrow means "then".
⚠️Catchup can surprise you
If a DAG has a start date in the past and catchup is on, Airflow creates a run for every missed interval at once. Decide on purpose whether you want that.

08Key Terms to Know

TermMeaning in easy words
DAGDirected Acyclic Graph: tasks and their dependencies, with no loops
TaskOne step in a DAG
OperatorA template that defines what a task does
SensorA task that waits for a condition, such as a file or another job
SchedulerThe component that creates runs and queues tasks that are ready
ExecutorThe part that decides how and where tasks run (local, Celery, Kubernetes)
Data intervalThe period of data a run is responsible for
Logical dateThe start of that interval, used to pick the right data
BackfillRunning a DAG for past intervals
CatchupAutomatically creating runs for missed intervals
IdempotentRunning again for the same interval gives the same result
XComA small message passed from one task to another
SLAA deadline for when a task or run should finish

09Pros, Cons and Trade-offs

✅ Pros
  • Clear order, retries and history for every run
  • Pipelines are Python code kept in Git
  • Large ecosystem of ready-made operators
  • Good UI for logs, failures and re-runs
  • Backfills make fixing past data easy
⚠️ Cons
  • Another system to run and keep healthy
  • Meant for scheduled batch work, not instant events
  • Time concepts (logical date) confuse beginners
  • Scheduler can slow with huge or slow-to-parse DAG files
  • Easy to misuse as a data processing engine

Trade-offs

ChoiceWe gainWe lose
Orchestrator instead of cronOrder, retries, UI, historyMore moving parts
Managed Airflow (cloud)Less operations workCost and less control
Many small tasksFine-grained retries and visibilityMore scheduling overhead
Few big tasksSimpler graphA retry repeats a lot of work
Sensors that waitStart as soon as data landsHold a worker slot unless set to reschedule

10Common Problems and Mistakes

Common mistakes

  1. Doing the heavy work inside Airflow. Big pandas jobs in a worker run out of memory. Trigger an engine built for it.
  2. Non-idempotent tasks. A retry or backfill appends the data a second time and creates duplicates.
  3. Using the current time inside a task. A re-run of an old interval reads the wrong data. Use the logical date.
  4. Big data in XCom. The metadata database fills up and slows down for everyone.
  5. Slow code at the top of a DAG file. The scheduler parses every file again and again. API calls or big imports there slow it all down.
  6. One giant DAG. A thousand tasks are hard to read and slow to schedule. Split by purpose.
  7. No alerts. A pipeline fails quietly on Friday night and nobody knows until Monday.

Things to watch

🪑Sensors holding slots
A sensor that just waits can use a worker for hours. Use reschedule mode or a deferrable sensor.
🕳️Missed or double runs
Daylight saving and time zones can shift a schedule. Prefer UTC.
🔐Secrets
Keep passwords in a secrets backend, not in DAG code.
🧮Concurrency
Set limits so a backfill does not hammer a database with 500 tasks at once.

11Real-World Examples

🏠Airbnb
Created Airflow in 2014 to manage its growing data pipelines. It is now an Apache project.
☁️Managed Airflow
Google Cloud Composer, Amazon MWAA and Astronomer run Airflow for you.
🧰Dagster and Prefect
Newer Python tools. Dagster focuses on data assets, Prefect on simple flows.
☸️Argo Workflows
Runs each step as a container on Kubernetes.
🪢AWS Step Functions
A managed state machine that links cloud services without servers.
📜Luigi and Oozie
Older orchestrators from Spotify and Hadoop. Still found in some companies.
📝Note
Airflow suits scheduled batch pipelines. For real-time event handling, use a stream processor or a queue instead.
Mini case: a safe re-run after a bug fix
🐞Bug found in cleanthree days of bad data
→↓fix, then clear 3 runs
🔁Backfill 3 dayseach overwrites its own partition
→↓no duplicates
✅Data correct
Because tasks write one partition per day and overwrite it, the replay is harmless.

12Related Topics to Read Next

ETL Pipelines→

The jobs that Airflow most often schedules.

Task Queues, Workers and Scheduled Jobs→

The simpler cousin: cron and queues.

Idempotency→

Why every task must be safe to run twice.

Spark and Hadoop→

The heavy engine Airflow usually triggers.

Batch vs Stream Processing→

Orchestrators are for batch work.

Alerts and Monitoring→

How failures reach a human.

SAGA Pattern→

Another way to run a multi-step flow with undo steps.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔Orchestrator: controls order, schedule, retries and alerts, and does not do the heavy work.
  • ✔DAG: tasks plus dependencies, no loops, written as Python code.
  • ✔Parts: scheduler, executor/workers, metadata DB, web UI.
  • ✔Time: a run covers a data interval and uses the logical date.
  • ✔Tasks must be idempotent: overwrite a partition, never blindly append.
  • ✔XCom: small values only. Real data goes in storage.
  • ✔Failure spreads: downstream tasks become upstream_failed. Parallel branches carry on.
  • ✔One line: “Airflow is the conductor: it says who plays when, and replays the bar when someone slips.”
← Previous
Spark and Hadoop
Next →
Parquet and Columnar File Formats