Skip to content
cccskills
FreePublished on GitHub

airflow-best-practices

Apache Airflow best practices for DAG authoring, testing, and production deployment

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md3.3 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Apache Airflow Best Practices (3.2.0)

DAG Authoring

Imports (Airflow 3.x)

  • Use from airflow.sdk import DAG, task, Asset — the stable public API
  • Legacy from airflow.models import DAG and from airflow.decorators import task are deprecated

Top-Level Code (CRITICAL)

  • Avoid heavy computation at module level (executed on every DAG parse)
  • Minimize imports at module level — lazy-load inside @task functions
  • Never call APIs, query databases, or access Variables at top level
  • If Variables needed at top level, enable experimental cache with TTL

TaskFlow API (Default Pattern)

  • Use @task decorator for all Python tasks (preferred over classic operators)
  • XCom serialization is automatic — return values become XCom
  • Use @task.branch for branching logic
  • Use @task.sensor for sensor tasks

Dynamic Task Mapping

  • Use task.expand() for runtime-determined task instances
  • Combine with .partial() for fixed kwargs
  • Map over lists, dicts, or XCom outputs from upstream tasks

Scheduling

  • Use cron expressions or timetables for schedule parameter
  • Set catchup=False for most DAGs
  • Use data-aware scheduling with Asset (replaces Dataset) for dependencies
  • Configure SLA monitoring

Task Dependencies

  • Use >> / << operators for clarity
  • Group related tasks with TaskGroup
  • Avoid deep nesting (max 3 levels)

Testing

Local Testing

  • Use dag.test() in if __name__ == "__main__": block for IDE debugging
  • Runs all tasks in single serialized process without executor

Unit Tests

  • Test DAG import without errors
  • Detect cycles in dependencies
  • Mock external connections
  • Test task logic independently

Integration Tests

  • Use Airflow test mode
  • Validate end-to-end workflows
  • Test with sample data

Production Deployment

Performance

  • Lazy-load heavy libraries inside @task functions
  • Use connection pooling
  • Minimize DAG parse time (target < 30s for all DAGs)
  • Enable parallelism appropriately

Reliability

  • Set appropriate retries and retry_delay
  • Use SLA callbacks for monitoring
  • Implement proper error handling with on_failure_callback
  • Log important events

Migration: 2.x → 3.x

Deprecated (Remove or Replace)

DeprecatedReplacement
from airflow.models import DAGfrom airflow.sdk import DAG
from airflow.decorators import taskfrom airflow.sdk import task
DatasetAsset
execution_date in contextdag_run.logical_date
conf in task contextRemoved — use Variables or params

Architecture Changes

  • AIP-72: Task Execution Interface — tasks run in isolated subprocesses via Execution API Server
  • AIP-44: Internal API — components communicate via API, not direct DB access
  • New UI: React-based web interface (replaces Flask-based UI)

References

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Pre-action boundary checking — validates agent tool calls against declared capabilities and task contracts

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Auto-detect project context and optimize harness — deactivate unused agents/skills, suggest missing experts, generate project profile

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Adversarial code review using attacker mindset — trust boundary, attack surface, business logic, and defense evaluation

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Alembic migration patterns for naming conventions, safety checks, expand-contract, env.py configuration, and CI integration

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Pre-routing ambiguity analysis — scores request clarity and asks clarifying questions when needed (inspired by ouroboros)

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

AWS patterns from Well-Architected Framework

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

See all skills by baekenough

Report a problem with this skill