ODCS contracts in practice: freshness, volume, schema
A data contract is a list of promises. "This table is fresh within 24 hours." "It has at least 1,000 rows." "It keeps these three columns." Each promise breaks for a different reason, at a different time, and lands on a different person's desk.
So treat each promise on its own. This post shows how Nistor reads a contract in the Open Data Contract Standard (ODCS), how it turns it into one dimension per promise, and how each dimension is measured.
One promise, one dimension
In Nistor, a data contract states what one or more assets promise, dimension by dimension. There are four dimensions, and each appears at most once in a contract:
freshness: breached when the last refresh is older thansla_hours;schema: breached when an expected column is missing or, if extra columns are not allowed, when an unexpected one appears;volume: breached when the latest row count is belowmin_rows, or moved more thanmax_delta_pctper cent from the previous one;quality: breached when fewer thanmin_pass_rateof the data-quality runs in the window passed.
A contract has a version and a status: draft, active or deprecated. Only active contracts are checked.
Every 30 minutes, Nistor checks each pair of asset and dimension. That is the unit that matters. A failing pair opens a
breach, a data_contract incident and a contract_breach alert. When the pair passes again, the breach and the
incident close and a contract_resolved alert goes out.
Because the check runs per pair, a late table does not hide a schema change, and a schema change does not hide a short load. Each promise keeps its own record.
The contract as a document
ODCS gives the promises a portable shape. Nistor supports version 3.1.0. It validates a document against the standard's JSON Schema, imports it, exports the live state of a node as a contract, and syncs a repository of contracts from CI.
The ODCS integration page shows a contract for a BigQuery table. Trimmed to the parts this post discusses, it reads:
apiVersion: v3.1.0
kind: DataContract
id: acme-orders
name: acme_orders
version: 1.0.0
status: active
schema:
- name: orders
physicalName: orders
physicalType: table
properties:
- name: order_id
physicalType: STRING
logicalType: string
required: true
primaryKey: true
- name: amount
physicalType: NUMERIC
logicalType: number
required: true
- name: ordered_at
physicalType: TIMESTAMP
logicalType: date
required: true
quality:
- type: library
rule: rowCount
dimension: completeness
mustBeGreaterOrEqualTo: 1000
slaProperties:
- property: latency
value: 24
unit: hours
element: orders.ordered_at
customProperties:
- property: nodeId
value: BigqueryTable_acme-data-prod.sales.orders
Nistor reads it in four steps.
The node. The nodeId custom property binds the contract to a node of the graph. A contract with no node is
stored, but projected onto nothing. Only the first object of schema is projected; the others stay in the stored
document.
The columns. The properties of that first object become the expected columns. required: true makes a column
non-nullable.
The SLA. A latency property becomes the freshness target, in hours.
The dimensions. This document produces dimensions on its Data Trust contract: schema with the three columns
(extra columns allowed), freshness at 24 hours, volume at a minimum of 1,000 rows from the rowCount rule, and
quality at a 95 per cent pass rate, because the contract has an executable rule.
Importing a contract that binds to a node also creates that node's monitored asset. An ODCS import is one of three ways to put an asset under Data Trust; the console and the API are the other two.
Freshness: the promise everyone notices
Freshness is measured from the health snapshots, which Nistor takes every 30 minutes. In the default mode, the latest successful run is the last refresh. The asset is fresh while that refresh is younger than its SLA.
A separate freshness evaluator runs every five minutes from the latest freshness observation: a tool's reading of the
source's last-modified time, or a successful run. For BigQuery, that reading uses tables.get, which runs no job and
bills nothing. The asset is at risk from 75 per cent of its SLA and in breach when the lag reaches it.
Freshness works in a pure open-source install. A ready-made version of this contract sits in the library as the freshness contract.
Schema: the promise that breaks on a deploy
Schema is measured against the node's columns in the graph. That means it follows the compiler: a change in the source appears once the compiler has picked it up.
Keep the expected columns to the ones consumers rely on. Declaring every column turns each harmless addition into a breach, if extra columns are not allowed. Schema works in a pure open-source install.
Volume: the promise you declare now and measure later
Volume is measured from row-count metrics, and those come from the Data quality module, part of
Nistor Enterprise. You can declare a volume dimension in open source, and the import keeps it. Without
the module, it has no data, so it never breaches. The same holds for the quality dimension.
Nistor treats that honestly. A pair that cannot be measured is skipped: it opens nothing and closes nothing. A dimension with nothing to measure is left out of the compliance score, so an unmeasured promise does not count as kept.
Reading compliance
A contract's compliance is the share of measured pairs that pass. On the contract's page, the console shows it by dimension, next to the open breaches. Changing a contract's dimensions cuts a new version, and the API lists the versions, so you can see when a promise was tightened.
The export closes the loop. It merges the stored contract under the live state of the node, so keys Nistor does not model, such as pricing, roles or retention, survive a round trip. Where they overlap, the live state wins.
Contracts as code
Keep the documents next to the pipelines. nistor odcs sync sends a directory of *.odcs.yaml files from CI,
validates each one, and imports it as a code-managed, locked contract. A file that fails is reported, and the batch
goes on. Nistor does not clone or fetch the repository itself: CI pushing the files is the supported path.
An import of an unchanged document is a no-op, because the stored copy is keyed on a hash of its content. Running the sync on every merge costs nothing when nothing changed.
A short checklist
- Bind every contract to a node with
nodeId. - Give freshness a target consumers can repeat from memory.
- Declare only the columns people depend on.
- Declare volume if you plan to measure it, and know it stays silent without the Data quality module.
- Read compliance by dimension, not as one number.
The data trust page shows contracts, SLOs and status pages in the console, and dashboard freshness SLOs puts a contract, an SLO and a status page behind a dashboard. The ODCS integration covers what each part of an import needs. The full format and the measurement rules are in the ODCS docs.