# datacontract.yaml — datacontract.com specification v0.9.3
dataContractSpecification: 0.9.3
# ─── Identity & Ownership ───────────────────────────────────────────────────
id: urn:datacontract:orders:v2
info:
title: Orders Domain — Enriched Orders
version: 2.1.0 # semver for THIS contract document
status: active # draft | active | deprecated | retired
description: |
Enriched order events produced by the Orders microservice after payment
gateway confirmation. One record per order state transition.
owner: team-orders # team slug or email group
contact:
name: Orders Platform Team
url: https://wiki.example.com/orders
email: orders-platform@example.com
links:
data_catalog: https://datahub.example.com/dataset/urn:li:dataset:(urn:li:dataPlatform:kafka,orders.enriched,PROD)
runbook: https://wiki.example.com/orders/runbook
slack: https://example.slack.com/archives/C0ORDERS
# ─── Terms of Use ────────────────────────────────────────────────────────────
terms:
usage: |
Data may be used for operational reporting and analytics. Re-publication
to external systems requires written approval from the Orders team.
limitations: |
PII fields must not be exposed in dashboards without masking. See
https://wiki.example.com/data-classification for the classification guide.
billing: free # free | subscription | metered
noticePeriod: P3M # ISO 8601 duration — 3-month deprecation notice
# ─── Servers (Where the Data Lives) ─────────────────────────────────────────
servers:
production_kafka:
type: kafka
host: kafka.example.com:9092
topic: orders.enriched.v2
format: avro # avro | json | protobuf
delimiter: none # newline | comma | none
description: Primary Kafka topic; compacted, Avro schema in Confluent Registry
environment: production
roles:
- name: read
description: Consumer group access
- name: write
description: Orders service producer access
production_s3:
type: s3
environment: production
location: s3://data-lake-prod/orders/enriched/v2/
format: parquet
delimiter: none
description: Daily Parquet snapshot synced from Kafka at 02:00 UTC
analytics_postgres:
type: postgres
environment: production
host: analytics-db.internal
port: 5432
database: analytics
schema: orders
description: Materialized serving layer for BI tools
# ─── Models (Schema) ─────────────────────────────────────────────────────────
models:
enriched_orders:
description: One row per order state transition with enriched customer data
type: table
fields:
order_id:
type: varchar
description: Globally unique order identifier (UUID v4)
required: true
unique: true
pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
example: "a3b2c1d0-e5f6-4a7b-8c9d-0e1f2a3b4c5d"
pii: false
customer_id:
type: varchar
description: Reference to the customer entity
required: true
references: customers.customer_id # cross-model FK hint
pii: false
customer_email:
type: varchar
description: Customer email address — PII, must be masked in marts
required: true
pii: true
dataClass: sensitive # sensitive | restricted | internal | public
classification: PII_EMAIL
order_status:
type: varchar
description: Current state in the order lifecycle
required: true
enum:
- CREATED
- PAYMENT_PENDING
- CONFIRMED
- SHIPPED
- DELIVERED
- CANCELLED
order_total_usd:
type: decimal
precision: 12
scale: 2
description: Total order value in USD including tax and shipping
required: true
minimum: 0
example: 149.99
pii: false
created_at:
type: timestamp
description: UTC timestamp when the order was first created
required: true
pii: false
updated_at:
type: timestamp
description: UTC timestamp of the most recent state transition
required: true
pii: false
metadata:
type: object
description: Opaque key/value bag for source-system flags
required: false
pii: false
fields:
source_system:
type: varchar
description: Originating microservice name
required: false
feature_flags:
type: array
description: Active feature flags at order creation time
required: false
# ─── Quality Checks (SodaCL) ─────────────────────────────────────────────────
quality:
type: SodaCL # SodaCL | montecarlo | custom
specification:
checks for enriched_orders:
# Completeness
- row_count > 1000:
name: Minimum daily row count
severity: error
- missing_count(order_id) = 0:
name: order_id must never be null
severity: error
- missing_count(customer_id) = 0:
name: customer_id must never be null
severity: error
- missing_percent(customer_email) < 1:
name: Email null rate under 1 %
severity: warning
# Uniqueness
- duplicate_count(order_id) = 0:
name: order_id must be unique
severity: error
# Value validity
- invalid_count(order_status) = 0:
name: order_status must be in allowed enum values
valid values: [CREATED, PAYMENT_PENDING, CONFIRMED, SHIPPED, DELIVERED, CANCELLED]
severity: error
- min(order_total_usd) >= 0:
name: No negative order totals
severity: error
# Freshness
- freshness(updated_at) < 2h:
name: Data must not be more than 2 hours stale
severity: error
# Custom SQL check
- failed rows:
name: No orders with DELIVERED status and zero total
fail query: |
SELECT order_id
FROM enriched_orders
WHERE order_status = 'DELIVERED'
AND order_total_usd = 0
severity: warning
# ─── Service Level Agreements ────────────────────────────────────────────────
servicelevels:
availability:
description: Kafka topic must be available 99.9 % of the time
percentage: 99.9%
retention:
description: Kafka topic retention; S3 data kept for 3 years
period: P7D # Kafka: 7 days ISO 8601 duration
unlimited: false
latency:
description: End-to-end latency from source event to topic
threshold: 30s
sourceTimestampField: enriched_orders.created_at
processedTimestampField: enriched_orders.updated_at
freshness:
description: New data must arrive every hour during business hours
threshold: 1h
timestampField: enriched_orders.updated_at
frequency:
description: Batch S3 snapshot produced once per day
type: batch
cron: "0 2 * * *"
tzinfo: UTC
support:
description: Business-hours support; critical incidents 24/7
time: 9am to 5pm CET, Mon-Fri
responseTime: 4h
# ─── Changelog ───────────────────────────────────────────────────────────────
# Follow semver: MAJOR.MINOR.PATCH
# MAJOR — breaking change (column removed, type narrowed, constraint added)
# MINOR — backward-compatible addition (new optional column, relaxed constraint)
# PATCH — non-schema changes (description update, SLA adjustment, contact info)
changelog:
- version: 2.1.0
date: 2025-11-01
author: orders-platform@example.com
description: |
Added `metadata` object field (optional, non-breaking).
Tightened freshness SLA from 4h to 2h (SLA-only change, MINOR).
- version: 2.0.0
date: 2025-09-15
author: orders-platform@example.com
description: |
BREAKING: Removed `legacy_order_ref` (VARCHAR) — deprecated in v1.5.0.
BREAKING: Changed `order_total` type from FLOAT to DECIMAL(12,2).
Consumers must migrate before 2025-09-15; use v1.x for backward compat.
- version: 1.5.0
date: 2025-06-01
author: orders-platform@example.com
description: |
Deprecated `legacy_order_ref`; will be removed in 2.0.0 (3-month notice).
Added `customer_email` field (optional in this version).