Lab: Enforcing a Contract and Shipping a Breaking Change
Write an Open Data Contract Standard (ODCS) v3.2.0 contract for an orders table, test it with the Data Contract CLI in the producer's CI, watch CI block a rename that would break consumers, then ship the rename as version 2 next to a deprecated version 1.
Contentsand lesson path
On this page
- Goal and setup
- Step 1: Run the producer job
- Step 2: Write the contract
- Step 3: Enforce it at the producer boundary
- Step 4: Watch CI block a breaking change
- Step 5: Classify the change before you ship it
- Step 6: Publish version 2 next to a deprecated version 1
- Step 7: Retire version 1 after the window
- Check your understanding
- Apply it
- Review prompt
Lessons of Data Contracts & Governance
- Data Products, Data Mesh and Contracts Between Teams Concept · 20 min
- Lab: Enforcing a Contract and Shipping a Breaking Change Lab · 25 min
- Lineage: Recording and Querying the Data Graph Worked example · 25 min
- Lab: Catalog Entries, Classification and Access Control Lab · 25 min
- Protecting Personal Data: Pseudonymize, Encrypt, Retain, Erase Worked example · 30 min
- Check: Governance Review of a Pipeline Knowledge check · 10 questions
What you will learn
- Write a data contract covering schema, semantics, quality expectations, freshness SLA, owner and version, enforce it at the producer boundary, and roll out a breaking change with a deprecation window.
01. Goal and setup
The checkout team publishes an orders table that finance and analytics read every morning. In this lab you are the checkout team. You will write the promise you make to those consumers as a data contract, check that promise automatically every time your job changes, and then make a change that would break consumers in the safe way: as a new major version, published next to the old one for a deprecation window.
You will use two open tools. The Open Data Contract Standard (ODCS) is a YAML format for contracts, maintained by the Bitol project of the Linux Foundation; version 3.2.0 is current. The Data Contract CLI reads an ODCS file, connects to the data and runs the checks the contract implies. Here the data lives in a DuckDB file so that everything runs on your laptop; the same contract can point at PostgreSQL, Snowflake, BigQuery or files in object storage.
You need Python 3.10 or later. The lab was tested with Python 3.12, datacontract-cli 1.2.10 and DuckDB 1.5.6.
mkdir contract-lab && cd contract-lab && mkdir data
python3 -m venv .venv && source .venv/bin/activate
pip install "datacontract-cli[duckdb]==1.2.10" "duckdb==1.5.6"contract-lab/
├── export_orders.py step 1, replaced in step 6: the producer's job
├── orders.odcs.yaml step 2, deprecated in step 6: contract version 1
├── orders-v2.odcs.yaml step 5: contract version 2
├── ci.sh step 3: the producer's CI check
└── data/shop.duckdb the published tables02. Step 1: Run the producer job
The job publishes 2,000 orders, generated from the row number so that everyone gets the same values. loaded_at records when the row was published, in UTC; the contract's freshness rule will read it.
"""The checkout team's job: publish yesterday's orders for other teams."""
import duckdb
con = duckdb.connect("data/shop.duckdb")
con.execute("""
create or replace table orders as
select 'ORD-' || lpad(i::text, 5, '0') as order_id,
1 + (i * 37) % 400 as customer_id,
timestamp '2026-11-15 00:00:00' + to_seconds(i * 41) as ordered_at,
(5 + (i * 53) % 4000 / 20)::decimal(10, 2) as amount,
['paid', 'refunded'][1 + (i % 9 = 0)::int] as status,
(current_timestamp at time zone 'UTC') as loaded_at
from range(1, 2001) t(i)
""")
print(con.sql("select count(*) as orders, sum(amount) as amount from orders"))python export_orders.py┌────────┬───────────────┐
│ orders │ amount │
│ int64 │ decimal(38,2) │
├────────┼───────────────┤
│ 2000 │ 208050.00 │
└────────┴───────────────┘03. Step 2: Write the contract
Read the contract from top to bottom. Each part answers a question a consumer would otherwise have to ask in a chat channel.
- Who and what version.
id,versionandstatusidentify the promise. The version follows semantic versioning: a major number for changes that can break consumers, a minor number for compatible additions, a patch number for fixes that change nothing consumers rely on.teamnames the owner, the person or team accountable when something is wrong. - What it means.
descriptiongives purpose, usage and limitations, and each property has a description. Semantics matter as much as types: "amount, including VAT, before any refund" stops each consumer from guessing. - Where it lives.
serverstells the CLI how to reach the data: a DuckDB file here. - What shape and quality.
schemalists the table's properties with types,requiredandunique.qualityadds rules: a SQL check that no amount is negative, a library metric thatstatusholds only known values, and a row count above zero. - How fresh.
slaPropertiesholds service levels. The freshness rule says the newestloaded_atmust be less than 6 hours old when checked.
apiVersion: v3.2.0
kind: DataContract
id: urn:shop:checkout:orders
name: orders
version: 1.0.0
status: active
domain: checkout
description:
purpose: One row per order placed in the web shop, for finance and analytics.
usage: Read the orders table after 06:00 UTC. Join to customers on customer_id.
limitations: Refunds are flagged in status; refunded amounts are not subtracted.
team:
name: checkout
members:
- username: [email protected]
role: owner
servers:
- server: shop
type: duckdb
database: ./data/shop.duckdb
schema: main
schema:
- name: orders
physicalName: orders
physicalType: table
properties:
- name: order_id
logicalType: string
required: true
unique: true
description: Order number, ORD- followed by five digits.
- name: customer_id
logicalType: integer
required: true
- name: ordered_at
logicalType: timestamp
required: true
description: When the customer placed the order, in UTC.
- name: amount
logicalType: number
required: true
description: Order value in euros, including VAT, before any refund.
quality:
- type: sql
description: No negative amounts.
query: SELECT COUNT(*) FROM {table} WHERE {column} < 0
mustBe: 0
- name: status
logicalType: string
required: true
quality:
- metric: invalidValues
arguments:
validValues: [paid, refunded]
mustBe: 0
- name: loaded_at
logicalType: timestamp
required: true
description: When this row was published, in UTC.
quality:
- metric: rowCount
mustBeGreaterThan: 0
slaProperties:
- property: freshness
element: orders.loaded_at
value: 6
unit: hlint checks the file against the ODCS JSON schema. test connects to the data and runs every check. The CLI prints a summary line with the run time, which differs on every run, so sed removes it. Each command takes several seconds to start. The result table is as wide as your terminal, so on a narrower window the same lines wrap at different places.
datacontract lint orders.odcs.yaml | tail -n 1 | sed -E 's/ Took .*//'
datacontract test orders.odcs.yaml | sed -E 's/ Took .*//'🟢 Data contract is valid. Ran 1 checks.
Testing orders.odcs.yaml
Server: shop (type=duckdb, database=./data/shop.duckdb, schema=main)
╭────────┬─────────────────────────────────────────────────────┬─────────────┬─────────╮
│ Result │ Check │ Field │ Details │
├────────┼─────────────────────────────────────────────────────┼─────────────┼─────────┤
│ passed │ Check that model orders has row_count > 0 │ │ │
│ passed │ Check that field 'amount' is present │ amount │ │
│ passed │ Check that field amount has type number │ amount │ │
│ passed │ Check that field amount has no missing values │ amount │ │
│ passed │ No negative amounts. │ amount │ │
│ passed │ Check that field 'customer_id' is present │ customer_id │ │
│ passed │ Check that field customer_id has type integer │ customer_id │ │
│ passed │ Check that field customer_id has no missing values │ customer_id │ │
│ passed │ Check that field 'loaded_at' is present │ loaded_at │ │
│ passed │ Check that field loaded_at has type timestamp │ loaded_at │ │
│ passed │ Check that field loaded_at has no missing values │ loaded_at │ │
│ passed │ Freshness of orders.loaded_at < 6h │ loaded_at │ │
│ passed │ Check that field 'order_id' is present │ order_id │ │
│ passed │ Check that field order_id has type string │ order_id │ │
│ passed │ Check that field order_id has no missing values │ order_id │ │
│ passed │ Check that unique field order_id has no duplicate │ order_id │ │
│ │ values │ │ │
│ passed │ Check that field 'ordered_at' is present │ ordered_at │ │
│ passed │ Check that field ordered_at has type timestamp │ ordered_at │ │
│ passed │ Check that field ordered_at has no missing values │ ordered_at │ │
│ passed │ Check that field 'status' is present │ status │ │
│ passed │ Check that field status has type string │ status │ │
│ passed │ Check that field status has no missing values │ status │ │
│ passed │ Check that field status has invalid_count = 0 │ status │ │
╰────────┴─────────────────────────────────────────────────────┴─────────────┴─────────╯
🟢 Data contract is valid. Ran 23 checks.You wrote five properties and three rules, and the CLI ran 23 checks. It derives most of them from the schema: every property must exist, have the declared type and, when required, have no missing values; a unique property must have no duplicates.
04. Step 3: Enforce it at the producer boundary
A contract that nobody runs is documentation. Enforce it where it can stop damage: in the producer's own CI, before new data or new code is published. ci.sh rebuilds the data with the job's current code, then lints and tests every contract in the folder. set -euo pipefail makes the script fail as soon as any command fails, and a failing script fails the CI job, which blocks the merge. In a CI service you would run this on every pull request against a disposable copy of the data. The CLI also has a ci command that adds GitHub Actions annotations.
#!/usr/bin/env bash
# The producer's CI job: build the data, then test every contract against it.
set -euo pipefail
export COLUMNS=88 # CI has no terminal: wrap the CLI's table at a fixed width
mkdir -p data
python export_orders.py > /dev/null
for contract in *.odcs.yaml; do
datacontract lint "$contract" > /dev/null
datacontract test "$contract" | sed -E 's/ Took .*//' | grep -E '^(🟢|🔴|[0-9]+\))'
donechmod +x ci.sh
./ci.sh; echo "exit code: $?"🟢 Data contract is valid. Ran 23 checks.
exit code: 005. Step 4: Watch CI block a breaking change
A developer on the checkout team decides that amount is ambiguous and renames it to amount_gross in the job. The rename is a good idea, but every consumer query that selects amount would fail tomorrow morning. Make the change and run CI. (The -i.bak form of sed works on both Linux and macOS and keeps a backup.)
sed -i.bak -e 's/ as amount,$/ as amount_gross,/' \
-e 's/sum(amount)/sum(amount_gross)/' export_orders.py
./ci.sh; echo "exit code: $?"🔴 Data contract is invalid, found the following errors:
1) amount Check that field 'amount' is present: Required column 'amount' is missing
2) amount Check that field amount has type number: Column 'amount' is missing
3) amount Check that field amount has no missing values: Column 'amount' not found
4) amount No negative amounts.: Error evaluating check: Binder Error: Referenced column
exit code: 1Long reasons are cut at the table width, as in line 4; datacontract test orders.odcs.yaml prints the whole message. CI fails, so the change never reaches consumers. The producer learns about the problem on their own pull request, while the change is still cheap to rethink. Put the original job back before you continue.
mv export_orders.py.bak export_orders.py06. Step 5: Classify the change before you ship it
The rename is still wanted, together with a new amount_net column. Write it as contract version 2.0.0: the same table name in the contract, published under the physical name orders_v2. Then let the CLI compare the two versions. breaking reports each difference with a severity from the consumer's point of view, and exits with code 1 if any change is breaking.
apiVersion: v3.2.0
kind: DataContract
id: urn:shop:checkout:orders
name: orders
version: 2.0.0
status: active
domain: checkout
description:
purpose: One row per order placed in the web shop, for finance and analytics.
usage: Read the orders_v2 table after 06:00 UTC. Join to customers on customer_id.
team:
name: checkout
members:
- username: [email protected]
role: owner
servers:
- server: shop
type: duckdb
database: ./data/shop.duckdb
schema: main
schema:
- name: orders
physicalName: orders_v2
physicalType: table
properties:
- name: order_id
logicalType: string
required: true
unique: true
description: Order number, ORD- followed by five digits.
- name: customer_id
logicalType: integer
required: true
- name: ordered_at
logicalType: timestamp
required: true
description: When the customer placed the order, in UTC.
- name: amount_gross
logicalType: number
required: true
description: Order value in euros, including VAT, before any refund.
quality:
- type: sql
description: No negative amounts.
query: SELECT COUNT(*) FROM {table} WHERE {column} < 0
mustBe: 0
- name: amount_net
logicalType: number
required: true
description: Order value in euros after refunds; 0 for a refunded order.
- name: status
logicalType: string
required: true
quality:
- metric: invalidValues
arguments:
validValues: [paid, refunded]
mustBe: 0
- name: loaded_at
logicalType: timestamp
required: true
description: When this row was published, in UTC.
quality:
- metric: rowCount
mustBeGreaterThan: 0
slaProperties:
- property: freshness
element: orders.loaded_at
value: 6
unit: hdatacontract breaking orders.odcs.yaml orders-v2.odcs.yaml | sed '/^Details/,$d'
echo "exit code: ${PIPESTATUS[0]}"Perspective: consumer
Summary
[ 2 Error ] [ 4 Info ]
╭──────────┬─────────┬───────────────────────────────────────╮
│ Severity │ Change │ Field │
├──────────┼─────────┼───────────────────────────────────────┤
│ INFO │ Updated │ description │
│ ERROR │ Updated │ schema.orders │
│ ERROR │ Removed │ schema.orders.properties.amount │
│ INFO │ Added │ schema.orders.properties.amount_gross │
│ INFO │ Added │ schema.orders.properties.amount_net │
│ INFO │ Updated │ version │
╰──────────┴─────────┴───────────────────────────────────────╯
exit code: 1Two changes are errors: the removed amount, and the changed schema.orders, because the data moved to another table. The new properties and the new version number are only information. This is why 2.0.0 is a major version, and why version 1 must stay available while consumers move.
07. Step 6: Publish version 2 next to a deprecated version 1
Replace the job with the version below. It builds orders_v2, then rebuilds orders from it with exactly the old columns and meaning. Then mark version 1 as deprecated in its contract: set status: deprecated, tell consumers what to use instead, and add an endOfLife service level with the date after which version 1 stops being published. The time until that date is the deprecation window. Announce it to the consumers listed for the table.
"""The checkout team's job, version 2: publish orders v2, and v1 until it retires."""
import duckdb
con = duckdb.connect("data/shop.duckdb")
con.execute("""
create or replace table orders_v2 as
select order_id, customer_id, ordered_at, amount_gross,
case when status = 'refunded' then 0 else amount_gross end as amount_net,
status, (current_timestamp at time zone 'UTC') as loaded_at
from (
select 'ORD-' || lpad(i::text, 5, '0') as order_id,
1 + (i * 37) % 400 as customer_id,
timestamp '2026-11-15 00:00:00' + to_seconds(i * 41) as ordered_at,
(5 + (i * 53) % 4000 / 20)::decimal(10, 2) as amount_gross,
['paid', 'refunded'][1 + (i % 9 = 0)::int] as status
from range(1, 2001) t(i)
)
""")
# Version 1 keeps its exact shape and meaning until its end of life.
con.execute("""
create or replace table orders as
select order_id, customer_id, ordered_at, amount_gross as amount, status, loaded_at
from orders_v2
""")
print(con.sql("select count(*) as orders, sum(amount_gross) as gross,"
" sum(amount_net) as net from orders_v2"))--- orders.odcs.yaml
+++ orders.odcs.yaml
@@ -5,3 +5,3 @@
version: 1.0.0
-status: active
+status: deprecated
domain: checkout
@@ -10,3 +10,6 @@
usage: Read the orders table after 06:00 UTC. Join to customers on customer_id.
- limitations: Refunds are flagged in status; refunded amounts are not subtracted.
+ limitations: >-
+ Deprecated. Use version 2.0.0 (table orders_v2), which renames amount to
+ amount_gross and adds amount_net. This version stops being published after
+ its end of life.
team:
@@ -63,2 +66,4 @@
slaProperties:
+ - property: endOfLife
+ value: "2027-01-31"
- property: freshnesspython export_orders.py
./ci.sh; echo "exit code: $?"┌────────┬───────────────┬───────────────┐
│ orders │ gross │ net │
│ int64 │ decimal(38,2) │ decimal(38,2) │
├────────┼───────────────┼───────────────┤
│ 2000 │ 208050.00 │ 184780.95 │
└────────┴───────────────┴───────────────┘
🟢 Data contract is valid. Ran 23 checks.
🟢 Data contract is valid. Ran 26 checks.
exit code: 0Both contracts pass. Consumers can now check that the two versions agree before they switch.
python -c 'import duckdb; db = duckdb.connect("data/shop.duckdb", read_only=True)
print(db.sql("select (select sum(amount) from orders) as v1_amount,"
" (select sum(amount_gross) from orders_v2) as v2_amount_gross"))'┌───────────────┬─────────────────┐
│ v1_amount │ v2_amount_gross │
│ decimal(38,2) │ decimal(38,2) │
├───────────────┼─────────────────┤
│ 208050.00 │ 208050.00 │
└───────────────┴─────────────────┘08. Step 7: Retire version 1 after the window
When the end-of-life date passes, check who still reads orders before you stop publishing it. Lineage events (the next lesson) and the warehouse's access logs both show the jobs and people that read a table. Contact the remaining readers, then remove the step that builds orders, set the old contract's status to retired and drop the table. Keep the retired contract in version control: it documents what the data meant while it existed.
09. Check your understanding
10. Apply it
This is the contract part of the skill practice. For the main output of a pipeline you built:
- Write an ODCS contract with owner, descriptions for every property, at least three quality rules and a freshness service level, and make the pipeline's CI run
datacontract testagainst a disposable copy. - Add a CI step that compares a changed contract with the version on your main branch using
datacontract breaking, and fails unless the major version was raised. - Write a short deprecation notice for a breaking change: what changes, the new version, the end-of-life date, and how consumers can check their migration.
11. Review prompt
Without looking back, explain: what each part of an ODCS contract promises and why semantics belong in it; why the contract is tested in the producer's CI rather than by consumers; how datacontract breaking decides that a change needs a new major version; and the steps of a breaking change, from the new version to retiring the old one.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.