Data Pipelines & ETL Orchestration: Apache Airflow & dbt

A data science model cannot run on stale data. Automated Data Pipelines ensure that raw records are extracted, validated, transformed, and loaded into feature stores on a scheduled, reliable cadence. In this class, we master pipeline orchestration with Apache Airflow and dbt.

Anatomy of an Apache Airflow DAG in Python

from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python import PythonOperator

# Default task arguments
default_args = {
    'owner': 'veewom_datascience',
    'depends_on_past': False,
    'start_date': datetime(2026, 1, 1),
    'email_on_failure': True,
    'email': ['alerts@veewom.com'],
    'retries': 2,
    'retry_delay': timedelta(minutes=5)
}

# Define DAG (runs every morning at 02:00 AM UTC)
with DAG(
    dag_id='daily_customer_churn_pipeline',
    default_args=default_args,
    schedule_interval='0 2 * * *',
    catchup=False
) as dag:

    def extract_transactions():
        print("Extracting raw transactions from production Postgres...")

    def run_feature_engineering():
        print("Transforming features & calculating rolling 30d spend...")

    def retrain_and_score():
        print("Running batch churn inference and saving to warehouse...")

    # Define tasks using PythonOperator
    task_extract = PythonOperator(task_id='extract_raw_data', python_callable=extract_transactions)
    task_transform = PythonOperator(task_id='engineer_features', python_callable=run_feature_engineering)
    task_score = PythonOperator(task_id='score_churn_predictions', python_callable=retrain_and_score)

    # Set dependency DAG execution order
    task_extract >> task_transform >> task_score

The Power of dbt (Data Build Tool)

Instead of writing hundreds of brittle boilerplate CREATE TABLE AS scripts, dbt allows data scientists to write modular SELECT statements: SELECT user_id, SUM(spend) FROM {{ ref('raw_orders') }} GROUP BY 1. dbt handles table builds, incremental updates, and schema testing automatically.

Frequently Asked Questions (FAQ) - Student & Interview Review

Q1. What is the difference between ETL and ELT?

In traditional ETL (Extract, Transform, Load), raw data is transformed by an intermediate compute engine before being loaded into a database. In modern ELT (Extract, Load, Transform), raw data is loaded directly into a cloud warehouse (BigQuery, Snowflake) and transformed in-place using powerful SQL engines (dbt).

Q2. What is an Apache Airflow DAG?

An Airflow DAG (Directed Acyclic Graph) is a collection of all the tasks you want to run, organized in a way that reflects their relationships, execution schedule, and dependencies in Python code. It is acyclic (no infinite loops allowed).

Q3. What is dbt (data build tool) and why is it popular?

dbt enables data scientists and analytics engineers to transform raw warehouse tables into clean analytical models using pure modular SELECT statements, automated version control, testing, and auto-generated data lineage documentation.

Q4. What is an Airflow Operator vs. a Sensor?

An Operator defines a single unit of work (e.g., PythonOperator, BashOperator, S3ToRedshiftOperator). A Sensor is a special operator that pauses execution and polls until a specific criteria is met (e.g., waiting for an external file to land in an S3 bucket).

Q5. How does Airflow handle task failures?

Airflow features automated retry policies (retries=3, retry_delay=timedelta(minutes=5)), SLA alerting, and email/Slack webhooks to notify engineers immediately on pipeline failure.

Explore Related Data Science Tutorials & Next Steps

Broaden your statistical analysis, Python data wrangling, and production engineering expertise:

Cloud Data Warehouses: BigQuery & Snowflake

Trigger ELT transformations using dbt within Apache Airflow DAGs.

FastAPI REST API Microservices

Orchestrate scheduled model retraining and registry updates.

Dockerizing Pipelines & CI/CD

Deploy containerized Airflow workers with Docker Compose.

12+ Hands-on Practice Labs & Datasets

Build an end-to-end automated ingestion pipeline from scratch.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!