Community研究与数据分析github.com

数据契约设计

定义并强制执行生产者与消费者之间的数据契约——明确的模式、语义、所有权、SLA 和版本控制——防止上游悄然变更导致下游管道中断。适用于生产者模式变更可能破坏消费者、定义团队/服务与数据仓库之间的接口,或在数据摄入时增加模式强制校验。

数据契约设计 是什么?

该技能专注于帮助工程师和 AI 代理设计并强制实施数据契约——这是数据平台工程的关键模式。数据契约作为管道的 API,通过 JSON Schema、Avro/Protobuf 等格式显式定义字段、类型、nullable 约束、语义、SLA、所有权和版本策略。核心工作流包括将契约作为版本化的代码存储、在摄入边界强制执行校验、将变更分类为向后兼容或破坏性变更,以及及时拒绝或隔离违规数据并通知生产者。该技能支持常见模式,包括使用 JSON Schema 进行摄入时校验、Kafka/Avro 模式注册表实现兼容性控制,并强调了常见陷阱,例如仅在文档中记录而不编码强制执行、在仓库深处而不是在边界捕获违规行为,以及缺乏版本控制或所有者。它适用于 Claude Code、Cursor、Codex 和 Spoon. 等平台,将运行时错误转化为可靠的数据质量信号。

兼容平台~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 项目内部的模型到模型变更(请使用测试 + 处理模式演化)。

契约规范内容

  • 模式:字段、类型、可空性和允许值。
  • 语义:每个字段的含义及其单位/粒度。
  • 保证:新鲜度/SLA、数据量预期、键的唯一性。
  • 所有权:谁生产数据以及联系谁。
  • 版本控制 + 变更策略:如何传达破坏性变更。

工作流程

- [ ] 将契约编写为版本化、已检入检查的模式(而非部落知识)
- [ ] 在摄入边界强制执行(到达时验证)
- [ ] 分类变更:添加性(安全) vs 破坏性(需要新版本)
- [ ] 违反时,拒绝/隔离并提醒生产者
- [ ] 提前版本化和传达破坏性变更
  1. 使其显式且版本化。 将契约作为代码(JSON Schema、Avro/Protobuf 模式或 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
}

强制执行点——在摄入时验证每条记录;将故障路由到带有原因的 隔离 位置,并提醒生产团队。这将一个无声的下游故障转化为一个立即的、有所有权的源头信号。

模式注册表(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.

相关技能