Say your team inherits an OrderUpdated event with 60 fields. Some are optional, a few come in two different shapes depending on which service sent them, and status means one thing from checkout and something slightly different from the warehouse. It looks complete. That's part of the problem. Everyone reads a different corner of it, and nobody can say which parts are safe to change. The most useful fix isn't another field. It's a smaller promise.
A data contract is the promise a producer makes to its consumers: an API response, an event on a queue, a table another team reads. This post is about keeping that promise small enough to explain, test and change without fear. We'll cover why wide contracts get stuck, how to write fields that mean one thing, how to handle new consumers, and the rules that keep changes safe.
Wide contracts promise more than you wrote
Hyrum Wright's observation, named Hyrum's Law by Titus Winters, says it best: "With a sufficient number of users of an API, it does not matter what you promise in the contract: all observable behaviors of your system will be depended on by somebody" (hyrumslaw.com). Field order, a value that happens to always be uppercase, an optional field that's never actually empty: if consumers can see it, someone will rely on it.
That's why the all-purpose payload ages badly. At first it's handy, because nobody has to ask for a change. A year later, producers are afraid to remove anything and consumers depend on behavior nobody ever reviewed. Every extra field is extra surface area someone can grab onto. A small contract keeps the surface area you have to defend small too.
Make every field mean one thing
Small contracts are easier to trust because they're easier to describe. This field means this. This value is always present. This amount is in this unit. This timestamp is UTC and set by this system. This ID belongs to this service. The language gets boring, which is a good sign.
Here's what that looks like as a JSON Schema for a payment event. Four required fields, each with a description that answers the questions people would otherwise ask in Slack:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "OrderPaid v1",
"type": "object",
"required": ["orderId", "amountMinor", "currency", "paidAt"],
"properties": {
"orderId": {
"type": "string",
"description": "Order ID, owned by the orders service"
},
"amountMinor": {
"type": "integer",
"minimum": 0,
"description": "Amount in the currency's smallest unit"
},
"currency": {
"type": "string",
"pattern": "^[A-Z]{3}$",
"description": "ISO 4217 code, e.g. VND or USD"
},
"paidAt": {
"type": "string",
"format": "date-time",
"description": "UTC time the payment provider confirmed the charge"
}
}
}
Note what's missing: no customer profile, no shipping address, no "just in case" fields. A consumer that needs those can ask, and that conversation is the useful part.
When a new consumer wants more
A small contract makes growth a visible decision. When a new consumer needs extra data, the team gets three real options instead of a silent "sure, I'll add it":
- Grow the contract, because the new field belongs to what this producer owns and several consumers will want it.
- Build a separate read model for that consumer, shaped for its screen or report. That's the idea behind CQRS.
- Push back, because the consumer is reaching across a boundary into data another service should own.
Ian Robinson's article on consumer-driven contracts (2006) gives this a structure. Each consumer states what it actually expects from the provider. Taken together, those expectations show which parts of the contract support real business value, and that tells the provider what it can change safely. Tools like Pact turn those expectations into tests that run in the provider's CI, so a breaking change fails a build before it breaks a consumer.
If you can't test it, you can't trust it
Testing is a good pressure test for a contract. If a promise is too vague to write a test for, it's too vague to rely on. A contract worth trusting comes with three things a future teammate can run without knowing the history:
- Examples: a few real-looking payloads, including the awkward ones (zero amount, a currency with no decimals, the oldest version still in use). The sibling post Name a Boundary, Then Give It Examples makes the same case for boundaries.
- Validation: the producer checks its output against the schema before publishing, so bad data stops at the source.
- Failure cases: what the consumer should do with a missing field, an unknown enum value or a duplicate message.
Change it without breaking anyone
Versioning gets much less dramatic when the contract is small, because there's less to keep compatible. A few rules from formats that have dealt with this for years:
- Adding is safer than changing. Protocol Buffers' guide says adding new fields is safe because old code ignores fields it doesn't know. Changing the number of an existing field isn't safe: it's the same as deleting the field and adding a new one (Protocol Buffers proto3 guide).
- Never reuse a removed field. Protobuf asks you to reserve deleted field numbers and names so nobody can accidentally reuse them later.
- Pick a compatibility rule and let a tool enforce it. Confluent Schema Registry defaults to BACKWARD compatibility (consumers on the new schema can still read data written with the old one), mainly so you can rewind consumers to the start of a topic (Schema Evolution and Compatibility).
- Read tolerantly. Martin Fowler's Tolerant Reader advises consumers to take only the fields they need and ignore the rest, so a producer adding a field doesn't break them.
Here's what removing a field looks like in protobuf, done the safe way:
syntax = "proto3";
message OrderPaid {
reserved 4;
reserved "legacy_status"; // removed in v3, never reuse
string order_id = 1;
int64 amount_minor = 2;
string currency = 3;
string paid_at = 5; // RFC 3339, UTC
}
Tolerant reading and Hyrum's Law pull in opposite directions, and that's fine. The producer keeps the promise small and changes it carefully. The consumer depends on as little as it can. Both sides shrink the surface area where things can break.
Try this week
- Pick one event or API your team owns. Count the fields and mark the ones no consumer actually reads.
- Add a one-line description to every field that doesn't have one: meaning, unit, owner.
- Write down which compatibility rule you follow, then check whether anything enforces it.
- Ask your two biggest consumers which fields they really use. That list is your contract.
Before adding the next field, check that the contract is still small enough to explain. If the team can name its owner, test what it means and list who depends on it, the contract is doing its job as part of the architecture.