Data engineering2 min read

Data contracts: stop upstream changes breaking everything downstream

A data contract is a promise between the team that produces data and the teams that depend on it. Here is how to put them in place without slowing anyone down.

Written by The metadatum team

Fibre optic cables connected to network equipment

Most pipeline failures don't start in the pipeline. They start upstream, when a source system renames a column, changes a type, or starts sending nulls where there never were any. Nothing tells the data team until a dashboard is wrong, and by then the people relying on it have stopped trusting the numbers.

What a data contract is

A data contract is an agreement, written down and enforced in code, about the shape and meaning of a dataset. It names the owner, the schema, the freshness guarantee, and what happens when any of those change.

PartWhat it coversEnforced by
SchemaColumns, types, nullabilityValidation at ingestion
SemanticsWhat each field meansDocumentation and review
FreshnessHow late data may arriveMonitoring and alerts
OwnershipWho to call when it breaksThe contract itself

How to put them in place

  1. Start with the three datasets that break most often, not all of them.
  2. Write the contract with the producing team, in their terms.
  3. Validate at the boundary, before anything lands in the platform.
  4. Fail loudly and early, with a message that names the owner.

A minimal schema check at ingestion looks like this:

from pydantic import BaseModel, Field

class Order(BaseModel):
    order_id: str
    customer_id: str
    amount: float = Field(ge=0)
    currency: str = Field(min_length=3, max_length=3)

def validate(rows: list[dict]) -> list[Order]:
    return [Order(**row) for row in rows]

Keep the contract alive

A contract nobody updates is worse than none, because people believe it. Store contracts next to the code that produces the data, review changes like any other pull request, and version them, so a breaking change becomes a new version that consumers move to on their own schedule.

What changes

Upstream teams learn about breaking changes before they ship them, not after. Downstream teams stop writing defensive code for problems that should never reach them. And when something does break, everyone knows whose problem it is.

  • AI

    Why AI pilots stall at the data, not the model

    A pilot that dazzles in a demo often falters in production. The reason is rarely the model. It is the data underneath it, and that is fixable.

  • Business intelligence

    One definition per metric: why your dashboards disagree

    When two reports show different revenue for the same month, the problem is rarely the maths. It is that the business never agreed what the number means.