24. Data contracts
A data contract is a product's written promise to its consumers: the schema, what each column means, the quality and freshness it keeps, who owns it, and its version. Checked before every release, it stops a breaking change before it ships.
The clip shows the six parts of the Claims product's contract: schema, meaning, quality promises, service levels, owner and version 1.0.0. The producer then makes two changes. Adding an optional column changes nothing a consumer reads: the check passes and it ships as 1.1.0. Renaming the reserve column is breaking: the check names the two systems it would break and stops the release. The rename then ships as version 2.0.0, served beside 1.0.0; the warehouse moves in month 1, the finance ledger in month 3, and 1.0.0 is retired in month 4.
The idea: a contract, a check, and versions
Chapter 23's product promised to be trustworthy. The contract is where that promise is written, in a form a machine can check. The Open Data Contract Standard (ODCS) gives it a shape:
- Schema and meaning: every column, its type, whether it is always filled or unique, its classification, and what it means.
- Quality and service levels: the rules the data passes, with thresholds, and how fresh it is and how long it is kept.
- Owner, status and version: who answers for it, whether it is active, and which version this is.
Then a check runs before every release: the new contract is compared with the published one, and each change is additive (a new optional column, a stronger promise: nobody breaks) or breaking (a column removed, renamed, retyped or made optional, a weaker promise). And versions say which: an additive change raises the minor version (1.0.0 to 1.1.0); a breaking one needs a new major version (2.0.0), served beside the old one until every consumer has moved.
A worked example: the Claims contract
The Claims contract promises 8 columns and 7 quality rules, data no older than 24 hours, kept 7 years, owned by Ruud Hendriks. Here it is as the Open Data Contract Standard writes it; CI checks it against the standard's own schema:
{
"apiVersion": "v3.1.0",
"kind": "DataContract",
"id": "dc-claims",
"name": "Claim: claims",
"version": "1.0.0",
"status": "active",
"domain": "Claim",
"dataProduct": "Claim",
"description": {
"purpose": "A loss reported against one policy.",
"usage": "Read by reporting, reserving and the claims assistant through the product's output port."
},
"team": {
"name": "Claim domain",
"members": [
{
"username": "ruud.hendriks@harbourmutual.example",
"name": "Ruud Hendriks",
"role": "owner",
"description": "Claims Director"
}
]
},
"schema": [
{
"name": "claims",
"physicalName": "claims",
"physicalType": "table",
"logicalType": "object",
"description": "A loss reported against one policy.",
"properties": [
{
"name": "claim_id",
"logicalType": "integer",
"physicalType": "integer",
"required": true,
"unique": true,
"primaryKey": true,
"primaryKeyPosition": 1,
"classification": "internal",
"description": "Surrogate key"
},
{
"name": "claim_number",
"logicalType": "string",
"physicalType": "text",
"required": true,
"unique": false,
"classification": "internal",
"description": "claim_number"
},
{
"name": "policy_id",
"logicalType": "integer",
"physicalType": "integer",
"required": true,
"unique": false,
"classification": "internal",
"description": "policy_id"
},
{
"name": "loss_date",
"logicalType": "date",
"physicalType": "date",
"required": true,
"unique": false,
"classification": "internal",
"description": "when the event happened"
},
{
"name": "reported_date",
"logicalType": "date",
"physicalType": "date",
"required": true,
"unique": false,
"classification": "internal",
"description": "when Harbour Mutual heard of it"
},
{
"name": "cause",
"logicalType": "string",
"physicalType": "text",
"required": true,
"unique": false,
"classification": "confidential",
"description": "cause"
},
{
"name": "status",
"logicalType": "string",
"physicalType": "text",
"required": true,
"unique": false,
"classification": "internal",
"description": "open, closed or rejected"
},
{
"name": "reserve",
"logicalType": "number",
"physicalType": "numeric(12,2)",
"required": true,
"unique": false,
"classification": "confidential",
"description": "what the insurer still expects to pay on an open claim"
}
],
"quality": [
{
"id": "rule-reported-after-loss",
"name": "A claim is reported on or after its loss date",
"dimension": "conformity",
"type": "sql",
"query": "SELECT 100.0 * AVG(CASE WHEN COALESCE(reported_date >= loss_date, FALSE) THEN 1 ELSE 0 END) FROM claims",
"mustBeGreaterOrEqualTo": 98,
"unit": "percent",
"severity": "warning"
},
{
"id": "rule-claim-reported-present",
"name": "A claim has a reported date",
"dimension": "completeness",
"type": "sql",
"query": "SELECT 100.0 * AVG(CASE WHEN COALESCE(reported_date IS NOT NULL, FALSE) THEN 1 ELSE 0 END) FROM claims",
"mustBeGreaterOrEqualTo": 99,
"unit": "percent",
"severity": "warning"
},
{
"id": "rule-claim-cause-known",
"name": "A claim's cause is on the loss-cause list",
"dimension": "conformity",
"type": "sql",
"query": "SELECT 100.0 * AVG(CASE WHEN COALESCE(cause IN ('collision', 'theft', 'windscreen', 'storm', 'escape of water', 'fire', 'medical', 'baggage'), FALSE) THEN 1 ELSE 0 END) FROM claims",
"mustBeGreaterOrEqualTo": 99,
"unit": "percent",
"severity": "warning"
},
{
"id": "rule-claim-reserve-range",
"name": "A reserve is between 0 and the large-loss limit of 100,000",
"dimension": "accuracy",
"type": "sql",
"query": "SELECT 100.0 * AVG(CASE WHEN COALESCE(reserve BETWEEN 0 AND 100000, FALSE) THEN 1 ELSE 0 END) FROM claims",
"mustBeGreaterOrEqualTo": 99,
"unit": "percent",
"severity": "warning"
},
{
"id": "rule-claim-reported-on-time",
"name": "A claim is reported within 60 days of the loss",
"dimension": "timeliness",
"type": "sql",
"query": "SELECT 100.0 * AVG(CASE WHEN COALESCE(reported_date - loss_date <= 60, FALSE) THEN 1 ELSE 0 END) FROM claims",
"mustBeGreaterOrEqualTo": 95,
"unit": "percent",
"severity": "warning"
},
{
"id": "rule-claim-number-unique",
"name": "Each claim number is used once",
"dimension": "uniqueness",
"type": "sql",
"query": "SELECT 100.0 * AVG(CASE WHEN COALESCE(NOT EXISTS (SELECT 1 FROM claims o WHERE o.claim_number = claims.claim_number AND o.claim_id <> claims.claim_id), FALSE) THEN 1 ELSE 0 END) FROM claims",
"mustBeGreaterOrEqualTo": 100,
"unit": "percent",
"severity": "error"
},
{
"id": "rule-claim-policy-exists",
"name": "A claim's policy exists",
"dimension": "consistency",
"type": "sql",
"query": "SELECT 100.0 * AVG(CASE WHEN COALESCE(EXISTS (SELECT 1 FROM policies r WHERE r.policy_id = claims.policy_id), FALSE) THEN 1 ELSE 0 END) FROM claims",
"mustBeGreaterOrEqualTo": 100,
"unit": "percent",
"severity": "error"
}
]
}
],
"slaProperties": [
{
"property": "freshness",
"value": 24,
"unit": "h"
},
{
"property": "retention",
"value": 7,
"unit": "y"
}
]
}
The claims team wants to rename reserve to reserve_eur. The check finds a breaking change: the column is read directly by Data warehouse, Finance ledger, so the release stops. The team publishes it as 2.0.0 beside 1.0.0 instead.
| Plan | Outcome |
|---|---|
| Publish 2.0.0 with reserve_eur and stop serving 1.0.0 the same day | A consumer breaks the day it ships |
| Publish 2.0.0 beside 1.0.0, and retire 1.0.0 in month 4, after every consumer has moved | Every consumer keeps working |
| Publish 2.0.0 beside 1.0.0, and retire 1.0.0 in month 2 | A consumer breaks when the old version is retired |
| Rename the column and publish it as 1.1.0 | A consumer breaks the day it ships |
| Add reserve_eur beside reserve in 1.1.0, then drop reserve in 2.0.0 in month 4 | Every consumer keeps working |
Why it matters for Alex
The merger will change the claims system more in a year than in the last ten. Every change is a chance to break the board report, the reserving and the reinsurer's file without anyone noticing until the numbers are wrong. Contracts checked in CI turn those surprises into a failed build on the producer's side, before it ships, with the consumers named.
Where it goes wrong
- A contract nobody checks. A document in a wiki is a wish. The check must run in the release pipeline and be able to stop it.
- Breaking changes as minor versions. Calling a rename 1.1.0 tells every consumer it is safe. It is not.
- Retiring the old version too soon. Switch off 1.0.0 before the last consumer has moved, and you broke it anyway, a month later.
- Only the schema. A contract with columns but no quality or freshness promises lets the data go wrong while the schema stays the same.
Exercises
The lab checks each one against facts written down in advance, so any answer the brief allows passes. A pass is kept in this browser.
Add a column without breaking anyone
The fraud team wants a fraud_score on every claim, a decimal number, empty for claims scored before the model existed. Add it to the Claims contract with a description that says what it means, change nothing a consumer relies on, and give the draft the version its change needs.
The lab checks that:
- The draft has an optional decimal column
fraud_score. fraud_scorehas a description of what it means, not just its name.- No change breaks a consumer.
- The version is a new minor version of 1: higher than 1.0.0, still 1.x.
Additive or breaking?
Each line is one change to the Claims contract. Choose what it is, and so which version it needs.
reserve to reserve_eur
fraud_score
cause be empty
claim_number is unique
status as confidential
Keep every consumer working
The rename of reserve to reserve_eur must ship. The warehouse team can move in month 1, the finance team in month 3. Choose what each plan does.
On Azure
Azure has no data contract service of its own; the pieces that work together:
- The contract in Git, next to the product's code, as an Open Data Contract Standard file, reviewed in a pull request like any code.
- The check in the release pipeline (GitHub Actions or Azure Pipelines): validate the file against the standard's schema, compare it with the published version, and stop the release on a breaking change without a new major version.
- The promises enforced in the platform: Delta tables in Microsoft Fabric or Azure Databricks refuse rows that do not fit the schema, constraints check required columns, and data quality rules in Microsoft Purview's Unified Catalog score the product against its thresholds.
- Versions side by side as two tables or views, such as claims_v1 and claims_v2, until the old one is retired.
Publish the contract with the product in the catalogue, so a consumer reads the promise before asking for access.
Take it to work
Data contract
Write the promise one data product makes to its consumers.
Fundamentals
- Product, domain, owner, status and version
Schema and meaning
- Each column: type, required, unique, classification, and what it means
Promises
- Quality rules with thresholds
- Freshness and retention
Changes
- What counts as breaking for these consumers?
- How long does an old major version run, and who decides when it is retired?
Consumers
- Who reads it, through which port, and how to reach them before a change
Tools in this chapter
- Contract editor · Write a data contract, validate it, and check whether a proposed change breaks its consumers.
Terms taught here: Data contractOpen Data Contract StandardBreaking changeService level