Lesson 5 of 5 Data Quality

Preventing Upstream Breakage with Data Contracts

This lesson explains how a data contract makes the expectations between a dataset's producer and its consumers explicit and enforceable, since many quality problems start when a producer changes a dataset without telling consumers.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify what a data contract contains.
  • Enforce each part of a contract with AWS tools.
  • Check contracts at the producer's boundary.

What a contract contains

A data contract is an agreement between the producer of a dataset and its consumers, written down so that both sides know what to expect. It defines the schema: the fields, their types and which are required. It defines the meaning of each field and the grain of the dataset, such as one row per order line, which prevents consumers from misinterpreting the data.

It also states quality rules and service levels, such as the rules every row must satisfy and that the data will be fresh by 06:00 each day, and it names the owner, the support contacts and the process for changing the contract, so that changes are negotiated rather than imposed.

Select all that apply

Inside a data contract

Exam skills 3.4.2 · 4.5.7

Identify what a data contract defines.

Log in to try this activity Interactive activities are free with an account.

Enforcing contracts

A data contract is an agreement between the producer and the consumers of a dataset. It covers the dataset's schema, quality, freshness and ownership, and each part needs its own enforcement. The schema of streaming data is enforced by the Glue Schema Registry, whose compatibility mode rejects breaking changes. The schema of lake tables is protected by managing Iceberg schema changes through review and by setting crawlers only to log schema changes, not apply them.

Quality rules run as Glue Data Quality rulesets in the producer's pipeline, so bad data is stopped at the source. Freshness is enforced with freshness rules and CloudWatch alarms. Ownership and terms are published with data products in SageMaker Catalog. The following table summarises the enforcement.

Contract elementEnforcement
Schema of streaming dataGlue Schema Registry with a compatibility mode
Schema of lake tablesIceberg schemas managed through reviewed changes; crawler change policies that only log
Quality rulesGlue Data Quality rulesets in the producer's pipeline
FreshnessFreshness rules and CloudWatch alarms
Ownership and termsPublished data products in SageMaker Catalog

The following diagram matches each contract element to its enforcement.

How each part of a data contract is enforced. Streaming schemas are checked by the Glue Schema Registry; lake table schemas change through reviewed Iceberg changes and crawlers that only log; quality rules run as Glue Data Quality rulesets in the producer's pipeline; freshness is watched by rules and alarms; and ownership and terms are published in SageMaker Catalog.
Enforcement runs at the producer's boundary where possible.
Match the pairs

Enforcing a contract

Exam skills 3.4.2 · 2.4.2

Match each contract element with how it is enforced.

Log in to try this activity Interactive activities are free with an account.

Enforcing at the producer

A contract is most effective when it is checked at the producer's boundary, before data is published. A breaking change then fails in the producer's own pipeline, where the producing team can fix it, instead of breaking every downstream team at once. This also supports data mesh designs, in which domains publish data products to agreed standards.

Worked example

A product team changed a customer field from a number to text, and three downstream pipelines failed overnight. The data platform team wants such changes caught before they are published.

Agree a data contract for the customer dataset, register its schema in the Glue Schema Registry with BACKWARD compatibility (or validate the table schema in the producer's CI pipeline), and run the contract's quality rules before publishing. The type change then fails in the product team's pipeline, and consumers are unaffected.

Check yourself

Where should a data contract be enforced?

Show answer

At the producer's boundary, before data is published.

Exam Tips

Remember for the exam

  • Data contracts define schema, semantics, quality and ownership between producers and consumers.
  • Enforce contracts at the producer's boundary, before data is published.
  • Schema registries enforce schema compatibility for streams.
  • SageMaker Catalog records ownership and publishes data products.
  • Contracts support data mesh designs.