📊 Data Engineering

Data Contract

Data Contract

An agreed schema and quality commitment between data producers and consumers.

Detailed Explanation

A Data Contract is a formal agreement between data producers and consumers that clearly defines the data's schema, quality standards, and SLA (Service Level Agreement). It has become a key mechanism for ensuring the reliability of data exchange between teams in microservice architecture and Data Mesh environments.

Like an API contract, a Data Contract is versioned, and when the schema changes, it either maintains backward compatibility or systematically manages Breaking Changes through prior consultation. The schema is defined in formats such as JSON Schema, Protocol Buffers, and Apache Avro, and quality rules are automatically validated with tools such as Great Expectations and Soda Core.

The key components include schema definition (field names, data types, required or not), quality rules (whether null is allowed, value ranges, uniqueness constraints), SLA (data delivery time, availability, freshness guarantees), and ownership information (producer team, contact, scope of responsibility).

Integrating Data Contract validation into the CI/CD pipeline makes it possible to detect contract violations early and prevent data quality problems from propagating to downstream systems. This forms the foundation of data governance and platform stability.

Code Example

YAML + Python
# data_contracts/orders_contract.yaml
# 주문 데이터 계약 정의

apiVersion: datacontract/v1.0
kind: DataContract
metadata:
  name: orders-events
  version: 2.1.0
  owner: order-service-team
  contact: order-team@company.com

info:
  title: 주문 이벤트 데이터 계약
  description: 주문 서비스에서 발행하는 주문 이벤트 스트림

schema:
  type: object
  properties:
    order_id:
      type: string
      format: uuid
      description: "주문 고유 식별자"
    customer_id:
      type: string
      pattern: "^CUS-[0-9]{10}$"
    order_date:
      type: string
      format: date-time
    status:
      type: string
      enum: [pending, confirmed, shipped, delivered, cancelled]
    total_amount:
      type: number
      minimum: 0
  required:
    - order_id
    - customer_id
    - order_date
    - status
    - total_amount

quality:
  - name: order_id_unique
    type: unique
    column: order_id
  - name: freshness
    type: freshness
    maxDelay: 5 minutes

sla:
  availability: 99.9%
  latency: p95 < 100ms

---
# Great Expectations 검증 (Python)
import great_expectations as gx

context = gx.get_context()
validator = context.get_validator(
    datasource_name="orders_stream",
    data_asset_name="orders"
)

# 데이터 계약 검증 규칙
validator.expect_column_values_to_not_be_null("order_id")
validator.expect_column_values_to_be_unique("order_id")
validator.expect_column_values_to_be_in_set(
    "status",
    ["pending", "confirmed", "shipped", "delivered", "cancelled"]
)
validator.expect_column_values_to_be_between(
    "total_amount", min_value=0
)

# 검증 결과 저장
validator.save_expectation_suite()
print("Data contract validation complete!")

Practical Conversation

Every time the upstream team's data changes, our pipeline breaks. What should we do?
You need to adopt a Data Contract. If you formalize the schema, quality rules, and change notification procedure with the upstream team, you can consult on Breaking Changes in advance. If you automatically validate with Great Expectations in CI, you can immediately know about contract violations.
How can data quality be ensured in a Data Mesh environment?
Each domain provides a Data Contract along with its data product. The schema is defined with JSON Schema or Avro, and the SLA and quality rules are specified. Consumers can trust the data based on the contract, and producers are responsible for complying with the contract.

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

This dbt model depends on the source table schema, but there is no schema change detection.
You need to add Data Contract validation. In the CI stage, check whether the source table's schema matches the contract, and have the pipeline stop if there is a mismatch. Add Great Expectations tests along with dbt's source freshness.

Cautions

  • Contract management creates overhead, so adopt it in stages, starting with core data assets.
  • A Data Contract requires a change in organizational culture. A sense of responsibility on the producer team must be a prerequisite.
  • Legacy systems may make schema extraction difficult, so a gradual migration strategy is needed.
  • Because tool standardization is still immature in this area, choose a format that suits your organization (YAML, JSON Schema, Protobuf).
  • Apply Semantic Versioning to contract versioning, and clearly mark Breaking Changes as a major version change.

Learn More