VAYULearn
Colour theme
Investigate a failure
VAYU Learn

Data Architecture & Reliability

Building Data Contracts - A Practical Implementation Guide

Data Contracts Sound Like Process Overhead Until Your Third Production Incident Caused by an Undocumented Schema Change.

Data Architecture & Reliability
A data contract isn’t documentation - it’s an enforced agreement between producers and consumers. When contracts are built into CI instead of wikis, schema changes stop becoming production incidents.

TL;DR

  • A data contract has four parts: schema, ownership, SLA, and semantic meaning — most teams that “have contracts” only have the first one, written down somewhere nobody enforces
  • Contracts written and contracts enforced are different metrics — a wiki page describing a schema is not a contract, it’s documentation nobody is required to keep accurate
  • Schema registries, dbt contracts, and Great Expectations can each enforce part of a real contract — no single tool gives you all four parts out of the box
  • Producer teams adopt contracts when the contract is the path of least resistance, not an extra template to fill out — enforcement in CI beats a request for goodwill every time
  • The incident that already happened is the best argument for adoption you will ever have — use it, don’t wait for the next one to make the case again

A contract nobody enforces is a wiki page with a more serious-sounding name.


The data platform team had rolled out “data contracts” six months earlier. Forty tables had contract documents — schema, description, a named owner, an SLA. All written in a shared wiki space. All reviewed once, at creation time.
A producer team changed a field’s type from string to int to fix a bug in their own system. Their contract document, sitting in the wiki, said the field was a string. Nobody checked the document before deploying. Nothing was wired to it. It was a description, not an enforcement mechanism.
The change broke two downstream pipelines. In the retro, someone pulled up the contract document and said, “well, at least we know what it was supposed to be.”
That sentence is the whole problem. A contract that only tells you what should have happened, after it already didn’t, isn’t a contract.

What a Data Contract Actually Contains

Most teams that say they have data contracts have written down a schema somewhere. A real contract is four things, and the failure in the opening story happened because only one of the four existed — and even that one wasn’t enforced.

Schema

The structural definition — field names, types, nullability. This is the part almost every “contract” effort actually produces, and the part covered extensively by the schema evolution practices in the previous post.

Ownership

A named team or person accountable for the data — not a Slack handle that was accurate two reorgs ago, but a maintained, checkable identity with an actual escalation path.

owner:
team: payments-platform
slack_channel: "#payments-platform-oncall"
pagerduty_service: "payments-data-pipeline"
escalation: "if no response in 30 min, page payments-platform-lead"

SLA

Freshness and availability guarantees — the same concept from the monitoring post in this phase, now made explicit as a producer commitment rather than something consumers discover empirically over time.

sla:
freshness_minutes: 15
availability_percent: 99.5
measured_over: "trailing 30 days"

Semantics

What each field actually means — the part almost every contract effort skips, and the part that would have prevented the semantic drift failure covered in an earlier post in this series (a field silently changing meaning while keeping the same name and type).

fields:
amount:
type: double
nullable: false
unit: USD
semantics: >
Gross transaction amount before fees. Refunds are represented
as negative values, not as a separate transaction type.
This field does NOT include the fee — see net_amount for that.

A contract missing this section looks complete because the schema still validates. It is not complete — it just hasn’t failed yet in a way anyone’s noticed.


Why Contracts Written and Contracts Enforced Are Different Things

The distinction the opening story makes obvious: a document describing a schema and a mechanism that prevents the schema from silently changing are not the same thing, even when they contain identical information.

Contract written:
A YAML file or wiki page exists describing the schema.
→ Provides zero protection. It can drift from reality
the moment anyone changes the underlying system
without updating the document.
Contract enforced:
A CI check, a schema registry compatibility mode, or a runtime
validation actively blocks a change that violates the contract.
→ Provides real protection, proportional to how much of the
contract is actually wired into an enforcement path.

The forty contracts in the opening story were all “written.” None of them were “enforced” in any way that would have stopped the type change from shipping. Measuring adoption by “contracts written” instead of “contracts enforced” is how a team ends up confident about protection it doesn’t actually have.


Tooling That Exists Today

Schema Registry as the Enforcement Layer

Covered in depth in the previous post — a schema registry with a configured compatibility mode enforces the schema portion of a contract at the moment a producer tries to publish an incompatible change. This is real, automatic enforcement, and it’s the most mature piece of the contract tooling landscape.

Purpose-Built Contract Tools

# dbt contracts — enforce schema at the model level
# models/schema.yml
models:
- name: transactions
config:
contract:
enforced: true
columns:
- name: amount
data_type: double
constraints:
- type: not_null
- name: transaction_id
data_type: string
constraints:
- type: not_null
- type: unique

dbt’s contract: enforced: true fails the model build if the actual output doesn't match the declared schema — real enforcement, scoped to the transformation layer rather than the streaming layer a schema registry covers.

# Great Expectations, covered in the previous phase post,
# is the tool that enforces the "semantics" section of a contract —
# not just that a field exists and has the right type,
# but that its values are plausible given what it's supposed to mean
validator.expect_column_values_to_be_between(
"amount", min_value=0.01, max_value=1_000_000,
meta={"notes": "Encodes the contract's stated business rule: "
"transactions above $1M route to manual review."}
)

No single tool covers all four parts. A schema registry enforces schema. dbt contracts enforce schema at the transformation layer. Great Expectations enforces semantic plausibility. Ownership and SLA enforcement, covered next, tend to be the parts teams have to build themselves.

The Minimal Viable Contract - YAML + CI

For teams without a mature schema registry or dbt contracts in place, a version-controlled YAML file checked in CI is a legitimate starting point — as covered in the schema evolution post, the enforcement value comes from the CI check, not the file format.

# ci/validate_contract.py
import yaml
from great_expectations.dataset import SparkDFDataset

def validate_against_contract(df, contract_path: str):
with open(contract_path) as f:
contract = yaml.safe_load(f)

ge_df = SparkDFDataset(df)
failures = []

for field in contract["fields"]:
col = field["name"]
if not field.get("nullable", True):
result = ge_df.expect_column_values_to_not_be_null(col)
if not result["success"]:
failures.append(f"{col}: contract requires not-null, found nulls")

if failures:
raise ContractViolation(f"Contract violations: {failures}")

This is meaningfully less sophisticated than a schema registry with compatibility enforcement, and it is still enforcement — it runs, it can fail a build, and it doesn’t depend on anyone remembering to check a wiki page.


Getting Producer Teams to Adopt Contracts

Why “Please Fill Out This Template” Fails

The most common rollout pattern — send producer teams a contract template, ask them to fill it in for their tables — produces exactly the outcome in the opening story. Forty documents, each accurate on the day it was written, drifting from reality the moment nobody’s incentive includes keeping it updated.

Making the Contract the Path of Least Resistance

Adoption happens when following the contract process is easier than not following it — not when it’s the responsible thing to do in the abstract.

Low adoption pattern:
"Please write a data contract for your tables and keep it updated."
→ Extra work, no immediate benefit to the producer team,
drifts the moment priorities shift elsewhere.
Higher adoption pattern:
"Schema changes to registered tables require passing a compatibility
check that's already wired into your existing CI pipeline.
No new process — it's the same PR merge process you already use,
with one more automated check."
→ The contract enforcement is invisible until it actually
catches something, at which point it looks like normal CI,
not an extra bureaucratic step.

The teams with the highest contract adoption make the contract enforcement indistinguishable from their existing deploy process — a check that runs automatically, blocks merges on real violations, and requires zero extra effort from a producer team that isn’t making a breaking change.

The Incident That Sells It

The opening story’s retrospective is, uncomfortably, the best adoption argument available. A team that has just lived through a production incident caused by an undocumented, unenforced schema change is far more receptive to “let’s wire a compatibility check into CI” than a team that hasn’t yet been burned.

Use the incident. Not to assign blame, but as the concrete, specific case for why the next version of the contract process needs enforcement, not just documentation. An abstract pitch about data governance rarely moves a producer team’s priorities. A recent, specific, costly incident usually does.


Enforcement Mechanisms That Work

CI-Level Enforcement

Covered above and in the previous post — schema compatibility checks and dbt contracts both belong here. This is the strongest, earliest point of enforcement: it stops a violation before it ever reaches production.

Runtime Enforcement

For the semantic and data-quality portions of a contract that can’t be fully checked at CI time (they require looking at actual data volumes and distributions), the Great Expectations and reconciliation patterns from earlier in this phase are the runtime enforcement layer — catching a contract violation after deployment but before it reaches a consumer that trusts the output.

Organizational Enforcement

The part no tool provides: an actual consequence when a contract is violated. This doesn’t need to be punitive — it can be as simple as a required retrospective any time a schema change breaks a downstream consumer, with the fix being an enforcement gap closed, not just an apology issued. Without this, even a well-built CI check can be bypassed under enough delivery pressure, and the organizational norm needs to make bypassing costly in attention and process, not just theoretically discouraged.

# A pattern some teams use: an explicit, auditable override
# rather than a silent bypass — makes the exception visible
# instead of invisible

def deploy_schema_change(schema, force_override: bool = False):
is_compatible = check_compatibility(schema)

if not is_compatible and not force_override:
raise ContractViolation(
"Schema change is incompatible. If this is intentional, "
"deploy with force_override=True and file an incident review."
)

if not is_compatible and force_override:
log_override_for_audit(
schema=schema,
approver=get_current_user(),
reason=get_override_justification()
)

An override path that requires an explicit, logged justification is very different from a check that’s easy to silently skip — it doesn’t prevent every bad decision, but it makes every bad decision visible and attributable.


The Data Contract Implementation Checklist

Contract completeness
□ Schema, ownership, SLA, and semantics are all documented —
not just schema
□ Ownership includes a real escalation path, not just a name
□ Semantics section explains what each field means, not just its type
Enforcement, not documentation
□ Schema portion is enforced via a registry or CI check, not a wiki page
□ At least one runtime check validates the semantic/data-quality portion
□ "Contracts enforced" is tracked as a metric, separate from
"contracts written"
Adoption
□ Contract enforcement is wired into existing CI, not a new
separate process producer teams must remember to run
□ A recent incident is used explicitly as the case for adoption
□ Override paths exist but require an explicit, logged justification
Maintenance
□ Contracts are reviewed when the underlying schema or business
logic changes, not left static
□ A contract that's been silently violated and unenforced for months
is treated as a finding, not ignored

Final Takeaway

The gap between the forty written contracts and the incident in the opening story wasn’t a documentation failure — it was an enforcement failure. The schema was written down accurately. Nothing was wired to check a real change against it before that change reached production.

A data contract is only as real as its enforcement path. Schema registries and dbt contracts enforce structure. Great Expectations and reconciliation enforce semantics and correctness. None of it works if adoption depends on a producer team remembering to update a document — it works when the contract is built into the same CI pipeline they were already going to run.

Core Principle

A contract you have to remember to check is not a contract. It is documentation with better branding. Enforce it, or it will drift the moment someone else's priority takes precedence over yours.

Next in Series

️AWS Data Engineering Cost Optimization - A Practical Audit

The cost-control pattern in this post — look at the specific line items, not the aggregate bill — applies just as directly to AWS, with a different set of services and cost centers.

Next: S3 storage and request costs, Glue job optimization, Athena query spend, Lambda execution costs, and the practical audit process for finding cloud waste before it compounds into the monthly bill.