Community연구 & 데이터 분석github.com

Airflow DAG 작성

TaskFlow API를 사용하여 프로덕션 등급의 Apache Airflow DAG를 작성합니다. 멱등성 태스크, 올바른 스케줄링 및 캐치업, 재시도/SLA, 연결/변수, 최상위 코드 회피 등을 다룹니다. Airflow DAG 생성 또는 리뷰, 파이프라인 스케줄링, 태스크 의존성 연결, 재시도/백필 설정, 비멱등성 태스크 수정 시 사용하세요.

Airflow DAG 작성란 무엇인가요?

이 스킬은 Apache Airflow에서 TaskFlow API를 사용하여 프로덕션에 적합한 DAG를 작성하는 방법을 가르쳐줍니다. 주요 초점은 태스크 멱등성, 올바른 스케줄링 및 캐치업 설정, 재시도 및 SLA 구성, XCom을 통한 데이터 전달, 연결/변수 사용, 그리고 최상위 코드에서의 무거운 연산 회피에 있습니다. 이 스킬은 DAG 생성/리팩토링, 파이프라인 스케줄링, 태스크 의존성 연결, 재시도/백필 구성, 또는 비멱등적 태스크 수정 시 유용합니다. Claude Code, Cursor, Codex 등과 같은 AI 에이전트를 위한 것이며, Airflow DAG 작성의 모범 사례를 안내하는 마크다운 문서를 제공합니다. 특히 각 태스크가 데이터 간격에 의해 매개변수화되고 멱등적이어야 하며, 스케줄러 부하를 방지하기 위해 무거운 임포트나 API 호출을 태스크 내부에 유지하고, `catchup`과 `schedule`을 의도적으로 설정하여 예상치 못한 백필을 방지하는 방법을 강조합니다. 또한 S3/GCS를 통한 대용량 데이터 전달, 연결/변수를 통한 비밀 관리, 태스크 내 `datetime.now()` 사용과 같은 일반적인 함정을 피하는 방법을 설명합니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Unknown-333/awesome-data-engineering-skills/tree/main/skills/authoring-airflow-dags

Installed? Explore more 연구 & 데이터 분석 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

Airflow DAG 작성은(는) 무엇을 하나요?

사용 시점

  • Airflow DAG 및 태스크 생성 또는 리팩토링 시
  • 스케줄, 캐치업/백필, 재시도 및 SLA 구성 시
  • 태스크 간 데이터 전달(XCom) 또는 연결/변수 사용 시
  • 실행 중인 손상된 DAG 진단에는 사용하지 마십시오. (대신 debugging-airflow-pipelines 사용)

워크플로우

- [ ] 각 태스크를 멱등적이게 만들고 데이터 간격에 의해 매개변수화
- [ ] 비용이 많이 들거나 임포트가 많은 코드는 모듈 최상위 레벨이 아닌 태스크 내부에 유지
- [ ] 스케줄 + 캐치업을 의도적으로 설정
- [ ] 재시도, retry_delay 및 SLA 구성
- [ ] TaskFlow 반환 값 또는 >> 연산자를 통해 의존성 연결
  1. 멱등성 태스크 — 2026-01-15 간격의 태스크는 한 번 실행되든 다시 실행되든 동일한 결과를 생성해야 합니다. datetime.now() 대신 데이터 간격을 사용하십시오.
  2. 무거운 최상위 코드 없음 — 스케줄러는 모든 DAG 파일을 자주 파싱합니다. 모듈 레벨에서의 데이터베이스 호출, API 호출 또는 큰 임포트는 스케줄링 속도를 늦추고 파싱을 중단시킬 수 있습니다. 이를 태스크 내부에 배치하십시오.
  3. 의도적인 스케줄 및 캐치업 — catchup=True는 start_date부터 모든 누락된 간격을 백필합니다. 원하지 않으면 기본값 False로 설정하십시오.
  4. 재시도 및 SLA — 일시적인 실패는 정상입니다. retries 및 retry_delay를 설정하고, 지연에 대해 SLA/알림을 사용하십시오.

패턴

TaskFlow DAG, 멱등적이고 깔끔하게 연결됨:

from airflow.decorators import dag, task
import pendulum

@dag(
    schedule="@daily",
    start_date=pendulum.datetime(2026, 1, 1, tz="UTC"),
    catchup=False,
    default_args={"retries": 3, "retry_delay": pendulum.duration(minutes=5)},
    tags=["orders"],
)
def orders_pipeline():

    @task
    def extract(data_interval_start=None):
        # now()가 아닌 간격을 사용하므로 재실행이 결정적입니다.
        return fetch_orders(day=data_interval_start.date())

    @task
    def load(rows):
        # 파티션을 삭제-삽입 -> 재시도 시 멱등성 보장.
        overwrite_partition("fct_orders", rows)

    load(extract())

orders_pipeline()

작은 데이터는 XCom(반환 값)을 통해 전달하고, 큰 데이터는 스토리지를 통해 전달 — S3/GCS/웨어하우스에 쓰고 경로/키를 전달하며, XCom으로 메가바이트를 절대 전달하지 마십시오.

연결/변수 사용 — 비밀 및 구성을 위해 (BaseHook.get_connection, Variable.get) 사용하고, 절대 하드코딩된 자격 증명을 사용하지 마십시오.

일반적인 함정

  • 최상위 API/DB 호출 또는 무거운 임포트 — 스케줄러 속도를 늦추고 전체 배포의 DAG 파싱을 실패시킬 수 있습니다.
  • 태스크 내부의 datetime.now() — 멱등성과 백필을 깨뜨립니다. data_interval_start/_end를 사용하십시오.
  • 의도하지 않은 catchup=True — 첫 배포 시 클러스터를 과거 실행으로 가득 채웁니다.
  • XCom을 통한 대용량 페이로드 — 메타데이터 DB를 부풀립니다. 참조를 전달하십시오.
  • 동적 start_date (예: days_ago) — 스케줄을 비결정적으로 만듭니다. 고정 타임스탬프를 사용하십시오.
  • 하나의 거대한 태스크 — 추출/변환/로드를 분할하여 재시도 단위를 세분화하십시오.

참조

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

Unknown-333/building-dagster-assets

Build Dagster pipelines using software-defined assets — asset dependencies, partitions, resources and IO managers, asset checks, and schedules/sensors. Use when creating Dagster assets or jobs, modeling data as assets, adding partitions or backfills, wiring resources/IO managers, or migrating from task-based orchestration to assets.

Unknown-333/building-dbt-models

Build well-structured dbt models — staging/intermediate/marts layers, ref() and source(), materializations, and incremental models with the right strategy. Use when creating or refactoring dbt models, choosing table vs view vs incremental, structuring a dbt project, or writing incremental logic.

Unknown-333/building-feature-pipelines

Build ML feature pipelines and feature stores — point-in-time-correct joins to avoid label leakage, offline/online parity, feature freshness and backfills, and materialization with tools like Feast. Use when engineering features for ML, preventing train/serve skew or data leakage, building a feature store, or backfilling historical features for training.

Unknown-333/building-iceberg-tables

Design and operate Apache Iceberg tables — partitioning and hidden partitioning, partition/schema evolution, snapshots and time travel, compaction and small-file cleanup, and MERGE/upsert for lakehouse tables on Spark, Flink, Trino, or Snowflake. Use when creating or maintaining Iceberg tables, choosing partitioning, evolving schema/partitions, or fixing small-file and metadata bloat.

Unknown-333/building-ingestion-pipelines

Build batch and incremental data ingestion (extract-load) pipelines — full vs incremental extraction, change data capture (CDC), watermarks and high-water marks, API pagination and rate limits, and choosing managed EL tools (Fivetran, Airbyte) vs custom code. Use when ingesting data from databases, APIs, files, or SaaS into a warehouse/lake, or designing incremental extraction and CDC.

Unknown-333/building-kafka-consumers

Build reliable Apache Kafka consumers and producers — consumer groups and partition assignment, offset commit strategy, at-least-once vs exactly-once, idempotent/transactional producers, rebalancing, and dead-letter handling. Use when writing Kafka consumers/producers, configuring offset commits or consumer groups, tuning throughput, or handling rebalances and poison messages.

Unknown-333/debugging-data-pipelines

Systematically root-cause data pipeline failures and data incidents — job errors, wrong or missing data, duplicates, and freshness misses — by tracing lineage upstream, isolating the failing stage, reconciling against source, and planning a safe fix and backfill. Use when a pipeline fails, numbers look wrong, data is missing or duplicated, a dashboard is stale, or a stakeholder reports a data discrepancy.

Unknown-333/designing-backfills-and-replays

Plan and run safe data backfills and replays — idempotent reprocessing of historical windows, partition-by-partition execution, isolating backfill compute from production, verifying results, and avoiding double-counting or changed history. Use when backfilling a new or fixed model, reprocessing after a bug, replaying events, or loading history for a new pipeline without corrupting existing data.

Unknown-333/designing-data-contracts

Define and enforce data contracts between producers and consumers — explicit schema, semantics, ownership, SLAs, and versioning — to prevent silent upstream changes from breaking downstream pipelines. Use when a producer schema change could break consumers, defining an interface between teams/services and the warehouse, or adding schema enforcement at ingestion.

관련 스킬