All skills
wshobson avatar

/airflow-dag-patterns

@be57c0b
by Seth Hobsonwshobson/agents40k stars
4,281

Build production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.

Use this Skill: https://skilld.dev/gh/wshobson/agents/airflow-dag-patterns

This session only. Nothing lands on disk.

SKILL.md

≈53 tokens always: the name and description. ≈724 when used: this file. ≈2.9k more on demand in 1 file.

Apache Airflow DAG Patterns

Production-ready patterns for Apache Airflow including DAG design, operators, sensors, testing, and deployment strategies.

When to Use This Skill

  • Creating data pipeline orchestration with Airflow
  • Designing DAG structures and dependencies
  • Implementing custom operators and sensors
  • Testing Airflow DAGs locally
  • Setting up Airflow in production
  • Debugging failed DAG runs

Core Concepts

1. DAG Design Principles

Principle Description
Idempotent Running twice produces same result
Atomic Tasks succeed or fail completely
Incremental Process only new/changed data
Observable Logs, metrics, alerts at every step

2. Task Dependencies

# Linear
task1 >> task2 >> task3

# Fan-out
task1 >> [task2, task3, task4]

# Fan-in
[task1, task2, task3] >> task4

# Complex
task1 >> task2 >> task4
task1 >> task3 >> task4

Quick Start

# dags/example_dag.py
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.operators.empty import EmptyOperator

default_args = {
    'owner': 'data-team',
    'depends_on_past': False,
    'email_on_failure': True,
    'email_on_retry': False,
    'retries': 3,
    'retry_delay': timedelta(minutes=5),
    'retry_exponential_backoff': True,
    'max_retry_delay': timedelta(hours=1),
}

with DAG(
    dag_id='example_etl',
    default_args=default_args,
    description='Example ETL pipeline',
    schedule='0 6 * * *',  # Daily at 6 AM
    start_date=datetime(2024, 1, 1),
    catchup=False,
    tags=['etl', 'example'],
    max_active_runs=1,
) as dag:

    start = EmptyOperator(task_id='start')

    def extract_data(**context):
        execution_date = context['ds']
        # Extract logic here
        return {'records': 1000}

    extract = PythonOperator(
        task_id='extract',
        python_callable=extract_data,
    )

    end = EmptyOperator(task_id='end')

    start >> extract >> end

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices

Do's

  • Use TaskFlow API - Cleaner code, automatic XCom
  • Set timeouts - Prevent zombie tasks
  • Use mode='reschedule' - For sensors, free up workers
  • Test DAGs - Unit tests and integration tests
  • Idempotent tasks - Safe to retry

Don'ts

  • Don't use depends_on_past=True - Creates bottlenecks
  • Don't hardcode dates - Use {{ ds }} macros
  • Don't use global state - Tasks should be stateless
  • Don't skip catchup blindly - Understand implications
  • Don't put heavy logic in DAG file - Import from modules

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides comprehensive patterns and best practices for creating Apache Airflow DAGs. It includes examples of task dependencies, TaskFlow API, dynamic DAG generation, branching, sensors, and testing. No security issues or malicious patterns were identified.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    1 file scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at be57c0b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 4 months ago
  • Testing
  • Python
  • airflow
  • dag
  • orchestration
  • data-pipeline
  • operators
  • sensors
  • deployment
  • workflow

README badge

README badge for wshobson/agents/airflow-dag-patterns

Provides patterns for building production Apache Airflow DAGs, covering operators, sensors, task dependencies, testing, and deployment strategies. Use when designing data pipelines, orchestrating workflows, or setting up Airflow in production environments.

Generated from the current SKILL.md.

Does this skill cover the TaskFlow API?
Yes. The skill recommends using the TaskFlow API for cleaner code and automatic XCom handling, though the quick-start example uses the traditional operator approach.
What testing approaches does this skill cover?
The skill mentions unit tests and integration tests as best practices but defers detailed testing patterns to the references/details.md file.
Does this include production deployment guidance?
The skill lists production setup and deployment strategies as core topics, but detailed deployment patterns are documented in the references/details.md file.
Can I use this skill for custom operators and sensors?
Yes. Implementing custom operators and sensors is listed as a use case, though specific implementation patterns are in the detailed references.
Does this cover Airflow's scheduler configuration and tuning?
The skill focuses on DAG design, operators, sensors, and deployment patterns rather than scheduler internals or tuning.

Generated from the current SKILL.md. These answers refresh after source changes.