
Apache Airflow DAG Patterns
FreeBuild production-ready Apache Airflow DAGs with best practices.
Free · Opens the source repo
What Apache Airflow DAG Patterns does
The Apache Airflow DAG Patterns skill provides developers and data engineers with a comprehensive guide to creating production-ready Directed Acyclic Graphs (DAGs) using Apache Airflow. This skill emphasizes best practices in DAG design, operator and sensor implementation, testing, and deployment strategies. It is particularly useful for those involved in data pipeline orchestration, as it helps streamline the process of designing and managing workflows effectively.
This skill covers essential concepts such as idempotency, atomicity, and observability, ensuring that users can create robust and reliable DAGs. It provides clear examples of task dependencies, ranging from linear to complex structures, allowing users to visualize how tasks interact within their workflows. The included quick start guide offers a practical example of an ETL pipeline, enabling users to quickly implement their own DAGs based on proven patterns.
In addition to the foundational principles, the skill outlines best practices that developers should follow, such as using the TaskFlow API for cleaner code and implementing timeouts to prevent zombie tasks. It also warns against common pitfalls, such as hardcoding dates or relying on global state, which can lead to complications in DAG execution. For users looking to deepen their understanding, the skill references detailed documentation in references/details.md, providing further insights and examples.
Overall, this skill is designed for data engineers and developers who need to create, test, and deploy workflows using Apache Airflow. By following the guidelines and patterns provided, users can enhance their workflow orchestration capabilities and ensure their data pipelines are efficient and maintainable.
When to use it
Use this skill when creating data pipelines, orchestrating workflows, or setting up Airflow in production environments.
When not to use it
This skill may not be suitable for users who are not working with Apache Airflow or those who require advanced customization beyond the provided patterns.
What you can build with it
Creating a Data Pipeline
Use this skill to design and implement a data pipeline using Apache Airflow, ensuring best practices are followed.
Debugging DAG Runs
Leverage the guidelines to troubleshoot and debug failed DAG runs effectively, minimizing downtime.
Implementing Custom Operators
Follow the patterns provided to create and integrate custom operators and sensors into your Airflow workflows.
How to install Apache Airflow DAG Patterns
View source1. Install with the skills CLI
npx skills add wshobson/agents/airflow-dag-patterns --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by wshobsonApache 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
Frequently asked questions about Apache Airflow DAG Patterns
Similar skills
Turborepo
Optimized build system for JavaScript/TypeScript monorepos.
Azure Pipelines Validation
Streamline your Azure DevOps pipeline changes locally.
Azure Developer CLI
Streamline your Azure project workflows with best practices.
Azure Container Registry CLI
Manage Azure Container Registry resources with ease.
Aspire
Build and orchestrate polyglot distributed applications seamlessly.
Vercel CLI
Manage and deploy Vercel projects from the command line.
