Data contract
A data contract is a formal, agreed-upon specification between a data producer and its consumers that defines the schema, format, semantics, and guarantees (like update frequency or backward-compatibility rules) of a dataset.
Overview
A data contract is an explicit agreement — sometimes documented, sometimes enforced in code — between whoever produces a dataset (an application team, a source system) and whoever consumes it (analytics, ML models, other services) about what that dataset looks like and how it will behave over time. It typically covers the schema (column names, types, nullability), semantics (what a column actually means and how it's calculated), delivery expectations (how often it updates, acceptable latency), and change-management rules (how and when the producer will notify consumers of breaking changes).
Data contracts emerged as a response to a common failure mode: an upstream engineering team changes a field's type, renames a column, or silently drops a field, and every downstream pipeline that depended on it breaks without warning. A contract makes those expectations explicit and, ideally, enforced automatically rather than discovered after something breaks.
What a contract typically specifies
- Schema: field names, types, and whether fields are required or optional
- Semantics: business meaning of each field (e.g. is
created_atin UTC or local time?) - Quality guarantees: constraints like uniqueness, non-null expectations, or valid value ranges
- Service-level expectations: freshness, delivery cadence, and support for schema evolution
- Ownership: who to contact when something looks wrong
Enforcement
Contracts are most useful when they're enforced, not just documented. This can mean validating incoming data against a schema before it's accepted into a pipeline, running automated tests that fail a build if a contract is violated, or using database-level constraints. A simple example of schema enforcement at the database level:
Copy code
CREATE TABLE orders (
order_id BIGINT PRIMARY KEY,
customer_id BIGINT NOT NULL,
order_amount DECIMAL(10,2) CHECK (order_amount >= 0),
status VARCHAR NOT NULL
);
Here, NOT NULL and CHECK constraints encode part of a contract directly into the table definition, rejecting rows that violate it rather than letting bad data flow downstream silently.
Why it matters
As organizations have more teams producing and consuming data independently, informal assumptions about "what a table means" break down. Data contracts formalize those assumptions, shifting failures left — catching a broken schema change at the source before it silently corrupts downstream reports or models, rather than after.
Related terms
A schema registry is a centralized service that stores, versions, and validates data schemas — typically for Avro, Protobuf, or JSON Schema — used to keep producers and consumers in streaming systems like Kafka compatible as schemas change.
Great Expectations →Great Expectations (GX) is an open-source Python framework for defining, running, and documenting automated data quality checks called Expectations.
Schema evolution →Schema evolution is the ability to change a table's structure — adding, removing, renaming, or reordering columns, or widening types — over time without needing to rewrite all existing data or break existing readers.
schema →A schema is a logical container or blueprint that defines how data is organized within a database.
Table format →A table format is a metadata layer on top of data files in a lake or object storage that defines what constitutes a table — its schema, partitioning, and file list — enabling ACID transactions, schema evolution, and time travel across multiple query engines.
Data observability →Data observability is the continuous, automated monitoring of data pipelines and datasets to detect freshness, volume, schema, and quality problems before they reach downstream users.
FAQS
A schema defines structure — column names and types. A data contract is broader: it includes the schema but also semantics, quality guarantees, freshness expectations, and change-management commitments between the producer and consumers of the data.
Typically the data producer is responsible for not breaking the contract (e.g. running validation before publishing changes), while consumers rely on automated tests or schema checks in their own pipelines to detect violations early if a contract is broken.
