Data Contract
Data Contract
An agreed schema and quality commitment between data producers and consumers.
Data Contract
An agreed schema and quality commitment between data producers and consumers.
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.
# 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!")
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free