Airflow DAG Patterns

Airflow DAG Patterns

Teaches an AI coding agent to build production Apache Airflow DAGs with sound operators, sensors, dependencies, testing and deployment patterns for data pipelines.

Skill files2 files

references/

SKILL.md116 lines
1
---
2
name: airflow-dag-patterns
3
description: 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.
4
---
5
6
# Apache Airflow DAG Patterns
7
8
Production-ready patterns for Apache Airflow including DAG design, operators, sensors, testing, and deployment strategies.
9
10
## When to Use This Skill
11
12
- Creating data pipeline orchestration with Airflow
13
- Designing DAG structures and dependencies
14
- Implementing custom operators and sensors
15
- Testing Airflow DAGs locally
16
- Setting up Airflow in production
17
- Debugging failed DAG runs
18
19
## Core Concepts
20
21
### 1. DAG Design Principles
22
23
| Principle | Description |
24
| --------------- | ----------------------------------- |
25
| **Idempotent** | Running twice produces same result |
26
| **Atomic** | Tasks succeed or fail completely |
27
| **Incremental** | Process only new/changed data |
28
| **Observable** | Logs, metrics, alerts at every step |
29
30
### 2. Task Dependencies
31
32
```python
33
# Linear
34
task1 >> task2 >> task3
35
36
# Fan-out
37
task1 >> [task2, task3, task4]
38
39
# Fan-in
40
[task1, task2, task3] >> task4
41
42
# Complex
43
task1 >> task2 >> task4
44
task1 >> task3 >> task4
45
```
46
47
## Quick Start
48
49
```python
50
# dags/example_dag.py
51
from datetime import datetime, timedelta
52
from airflow import DAG
53
from airflow.operators.python import PythonOperator
54
from airflow.operators.empty import EmptyOperator
55
56
default_args = {
57
'owner': 'data-team',
58
'depends_on_past': False,
59
'email_on_failure': True,
60
'email_on_retry': False,
61
'retries': 3,
62
'retry_delay': timedelta(minutes=5),
63
'retry_exponential_backoff': True,
64
'max_retry_delay': timedelta(hours=1),
65
}
66
67
with DAG(
68
dag_id='example_etl',
69
default_args=default_args,
70
description='Example ETL pipeline',
71
schedule='0 6 * * *', # Daily at 6 AM
72
start_date=datetime(2024, 1, 1),
73
catchup=False,
74
tags=['etl', 'example'],
75
max_active_runs=1,
76
) as dag:
77
78
start = EmptyOperator(task_id='start')
79
80
def extract_data(**context):
81
execution_date = context['ds']
82
# Extract logic here
83
return {'records': 1000}
84
85
extract = PythonOperator(
86
task_id='extract',
87
python_callable=extract_data,
88
)
89
90
end = EmptyOperator(task_id='end')
91
92
start >> extract >> end
93
```
94
95
## Detailed patterns and worked examples
96
97
Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
98
99
## Best Practices
100
101
### Do's
102
103
- **Use TaskFlow API** - Cleaner code, automatic XCom
104
- **Set timeouts** - Prevent zombie tasks
105
- **Use `mode='reschedule'`** - For sensors, free up workers
106
- **Test DAGs** - Unit tests and integration tests
107
- **Idempotent tasks** - Safe to retry
108
109
### Don'ts
110
111
- **Don't use `depends_on_past=True`** - Creates bottlenecks
112
- **Don't hardcode dates** - Use `{{ ds }}` macros
113
- **Don't use global state** - Tasks should be stateless
114
- **Don't skip catchup blindly** - Understand implications
115
- **Don't put heavy logic in DAG file** - Import from modules
116

© Seth Hobson · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 11,967 prompts

More by @OpenSourceBuffGuy

See all
Acid Lime 3D Streetwear Type Poster Style prompt image

Acid Lime 3D Streetwear Type Poster Style

Defines a JSON style for glossy 3D streetwear campaign posters with black block type, acid-lime marker strokes, stickers and fashion props, with fill-in variables.

image-prompt, json-prompt, template, placeholders, 3d-render, fashion, toys, poster, vibrant-colors, studio-lighting, low-angle, sticker, typography, text-rendering, structured-output, style-reference, negative-prompt, for-designers, for-marketers, long-form, advanced

Azure Static Web Apps prompt image

Azure Static Web Apps

Helps an agent create, configure and deploy Azure Static Web Apps with the SWA CLI, including local emulation, Functions APIs and CI/CD.

agent-skill, azure, deployment, github-actions, ci-cd, serverless, command-line, frontend, step-by-step-guide, for-developers, best-practices, authentication, web-development, scaffolding, cloud, api, nodejs

Workflow Automation Specialist prompt image

Workflow Automation Specialist

Finds repetitive tasks to automate, estimates time savings and ROI, and designs no-code workflows with Zapier, Make or native tools within your budget.

system-prompt, expert-advice, workflow-automation, no-code, productivity, zapier, make-com, for-non-coders, for-small-business-owners, beginner-friendly, xml-tags, estimation, planner, guardrails, structured-output, process-improvement, step-by-step-guide, consulting, time-management, office-administration

Reviews

Loading reviews…

Discussion

Loading comments…