{"canonical_url":"https://engineer.company/glossary/data-contract/","content_markdown":"# Data contract\n\n## What it is\n\nA data contract records what a producer and its consumers can rely on when data\ncrosses a boundary. It can describe fields, identifiers, units, allowed values\nand the grain of a record. It can also identify owners, freshness requirements,\nquality checks, and how changes will be introduced. The contract gives teams a\nshared basis for deciding whether a new delivery can be used safely.\n\nA schema is often part of the contract. The schema might require a decimal field\nand a timestamp, for example. The contract can say that the decimal is expressed\nin a named currency, that the timestamp is the moment the source recorded a\ncompleted sale, and that every row represents one sale. The schema makes a\nportion of that agreement checkable by software. The unit, historical meaning\nand freshness may need additional checks or documented policies.\n\nAn effective contract connects its promises with evidence. Types can be tested\nas part of a build. An example payload can show how a cancellation is\nrepresented. A test against the published dataset can check that each expected\ndate is present. The agreement becomes easier to maintain when the parties can\nfind the definition, verify the behaviour, and identify who can approve a\nchange.\n\n## Why it matters\n\nA producer can make a breaking change while the shape of the payload still\nvalidates. Suppose a report reads an amount that has always been stored in\ncents. The producer decides to write whole units of the currency to simplify a\nnew integration. The values can still fit the same numeric type. An existing\nconsumer divides them by one hundred and publishes numbers that look plausible\nat a glance. The contract needs to specify the unit and the transition policy,\nso a review can distinguish a formatting adjustment from a different business\ninterpretation.\n\nSparse fields raise a similar issue. A field can be missing because a producer\nhas not collected it yet. An explicit null could signal that the value was\nchecked and is unknown. An empty string might mean a user cleared a label. Those\ndistinctions affect transformations and reporting. Preserve them where consumers\ndepend on them, and include an example of each permitted state. An example\nshould establish what the recipient can infer, especially when a new field is\noptional during a rollout.\n\nThe agreement also reduces uncertainty when data arrives late or fails a check.\nA daily report may use a stable published snapshot if its inputs have not\narrived. An automated stock decision might require current data and need to stop\nor route the request elsewhere. Freshness is useful when it is written as an\nobservable condition and paired with a recovery path. Name the expected\nschedule, how delay is detected, and who decides when to release an adjusted\ndataset.\n\n## What it looks like in practice\n\nConsider a feed that provides completed sales to a finance system. It records\nthe sale identifier, time of completion, currency and amount in minor units. One\nversion of the contract defines when a sale appears, how a later cancellation is\nrepresented and whether repeated deliveries are possible. It also specifies\nwhich business day a sale belongs to when stores operate across timezones. Put a\nnormal sale, a cancellation and a delayed record in the examples so those\ndecisions are visible to both sides.\n\nRun checks at the boundary that can observe each promise. A producer test can\nensure the amount is encoded in minor units and the timestamp is present. A\nconsumer fixture can verify that a cancellation reverses the intended sale. A\npublished-data check can detect duplicate identifiers or a missing day. Each\nfailed check should say which promise was broken and point to its owner. Changes\nto units, meaning or record grain deserve review alongside changes to field\nnames and types.\n\nEngineer's\n[database-to-API contract case study](/portfolio/generated-the-api-contract-from-the-database-out/)\ndescribes generating an OpenAPI description, a typed TypeScript client and\nfrontend test fixtures from connected sources of truth. The work also checks\ndetails that can drift, including the distinction between optional fields and\nexplicit null values. A data-feed contract can use the same idea of exercising\nboth sides with concrete examples. Generation removes some manual copies, and\nverification gives the producer and consumers evidence that the published\nbehaviour still matches the agreed meaning.\n\n## Where it goes wrong\n\nA contract stored beside the code can become stale when the build and the\npublished data carry no check connected to it. Choose a small set of promises\nimportant enough to enforce and attach each to an owner and a test. A generated\nschema can make a change visible in review. A measured dataset check can show\nwhen the running system still fails a requirement even though the build accepts\nits source.\n\nCompatibility also depends on which consumers still exist. A new application can\nhandle an added field by using a default when it reads older records. An older\nconsumer may reject unexpected fields or rely on a meaning that changed without\na new field. Record the support window, test the relevant producer and consumer\ncombinations, and coordinate a revised dataset before removing the old\nrepresentation. Keep a useful version identifier and a route for discovering\nwhich version a particular delivery used.\n\nA contract gives a team a way to respond to failures. It also needs a\nproportionate response. A harmless optional label might justify a warning, while\na missing currency can require isolation of the records before a financial\nreport runs. Treat exceptions as observable decisions with an expiry and an\nowner. Test a late delivery and a refused record explicitly. The resulting\nevidence makes it easier to restore confidence in a dataset after its producer\nor consumers change.\n\n## Further reading\n\n- [The Open Data Contract Standard](https://bitol.io/odcs/). Introduces an open\n  format for schema, quality, support and other data agreements.\n- [The Open Data Contract Standard specification repository](https://github.com/bitol-io/open-data-contract-standard).\n  Provides versioned definitions and examples.\n- [Confluent data contracts](https://docs.confluent.io/platform/current/schema-registry/fundamentals/data-contracts.html).\n  Describes contracts and rule enforcement around serialized streams.\n\n\u003chttps://engineer.company/glossary/data-contract/\u003e\n","date_modified":"2026-11-25T07:18:46Z","description":"Specify grain, currency, freshness and ownership for a shared feed, and test whether producers meet the agreement.","formats":{"gemtext":"https://engineer.company/glossary/data-contract/index.gmi","gopher":"https://engineer.company/glossary/data-contract/gophermap","html":"https://engineer.company/glossary/data-contract/","json":"https://engineer.company/glossary/data-contract/index.json","markdown":"https://engineer.company/glossary/data-contract/index.md","pdf":"https://engineer.company/glossary/data-contract/index.pdf"},"kind":"page","language":"en","title":"What is a data contract?","url":"https://engineer.company/glossary/data-contract/","version":1}