Community研究與資料分析github.com

設計資料契約

定義並強制執行資料生產者與消費者之間的資料契約 — 包含明確的綱要、語義、擁有權、SLA 及版本管理 — 防止上游的潛在變更破壞下游管線。

設計資料契約 是什麼?

此技能旨在協助開發者設計並強制執行資料契約,當上游變更可能無聲無息地破壞下游管線時,提供明確的介面定義與驗證機制。它特別適用於服務/事件/API/檔案等上游資料饋送下游管線的情境,或者需要在團隊之間、服務與資料倉儲之間定義介面,以及在資料擷取邊界加入綱要與品質強制執行時。支援的平台包含多種資料管線與事件串流系統,例如 Kafka、Avro、以及 JSON Schema 等技術。此技能強調將契約以程式碼形式(如 JSON Schema、Avro/Protobuf schema 或 YAML 規格)版本化管理,並在資料抵達時立即驗證,違規則拒絕或隔離並通知生產者,從而將無聲的下游錯誤轉變為即時、有歸屬的訊號。常見陷阱包括僅將契約視為書面文件而未實際執行、在倉庫深處才進行驗證、缺乏版本管理、未設擁有者等。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Unknown-333/awesome-data-engineering-skills/tree/main/skills/designing-data-contracts

Installed? Explore more 研究與資料分析 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

設計資料契約 是做什麼的?

使用時機

  • 上游(服務、事件、API、檔案)饋送下游管線,且變更可能無聲破壞管線時。
  • 定義生產團隊/系統與資料倉儲之間的介面。
  • 在擷取邊界加入綱要/品質強制執行。
  • 不適用於 同一 dbt 專案內的內部模型到模型變更(請使用測試 + handling-schema-evolution)。

契約應指定內容

  • 綱要:欄位、型別、可空性及允許值。
  • 語義:每個欄位的意義及其單位/粒度。
  • 保證:新鮮度/SLA、資料量預期、鍵的唯一性。
  • 擁有權:誰生產資料以及聯絡人。
  • 版本管理 + 變更政策:如何溝通破壞性變更。

工作流程

- [ ] 將契約寫成版本化、可簽入的綱要(非 tribal knowledge)
- [ ] 在擷取邊界強制執行(資料到達時驗證)
- [ ] 分類變更:新增(安全) vs. 破壞性(需要新版本)
- [ ] 發生違規時,拒絕/隔離並通知生產者
- [ ] 提前版本化並溝通破壞性變更
  1. 明確且版本化。 將契約以程式碼形式儲存(JSON Schema、Avro/Protobuf schema 或 YAML 規格),置於管線旁,像 API 一樣接受審查。
  2. 在邊界強制執行。 資料到達時立即依據契約驗證;違規則拒絕或隔離,而非載入。
  3. 分類變更。 新增/選用欄位 = 向後相容。移除欄位、重新命名、收緊型別/可空性 = 破壞性 → 新版本。
  4. 向生產者大聲失敗,而非在下游無聲破壞。

模式

契約以 JSON Schema 形式(在擷取時強制執行):

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["order_id", "amount", "ordered_at"],
  "properties": {
    "order_id": { "type": "string" },
    "amount": { "type": "number", "minimum": 0 },
    "ordered_at": { "type": "string", "format": "date-time" },
    "coupon": { "type": ["string", "null"] }
  },
  "additionalProperties": false
}

強制執行點 — 在資料擷取時驗證每一筆記錄;將失敗記錄路由至附有原因的 quarantine 位置,並通知生產團隊。如此可將無聲的下游錯誤轉變為即時、有歸屬的來源訊號。

Schema Registry(Kafka/Avro) — 在發佈時強制執行相容性(BACKWARD),使生產者無法發佈不相容的綱要。

常見陷阱

  • 契約僅作為文件 — 若未在程式碼中強制執行,它會偏移並無聲破壞。
  • 在資料倉庫深處執行 — 應在邊界捕捉違規,避免不良資料擴散。
  • 無版本管理 — 每次變更都變成緊急事件;應版本化並優雅地棄用。
  • 未限制 additionalProperties 當你需要嚴格性時 — 意外欄位會溜進來;視情況設為 false。
  • 無擁有者 — 被拒絕的批次若無人可聯絡,會使管線停滯。
  • 破壞性變更無預告期 — 應透過版本化綱要與棄用窗口協調生產者/消費者。

Individual skills in this repo

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

Unknown-333/authoring-airflow-dags

Write production-grade Apache Airflow DAGs using the TaskFlow API — idempotent tasks, correct scheduling and catchup, retries/SLAs, connections/variables, and avoiding top-level code. Use when creating or reviewing Airflow DAGs, scheduling pipelines, wiring task dependencies, configuring retries/backfills, or fixing non-idempotent tasks.

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.

相關技能