↓Skip to main content

3 places to validate data contracts

The difference is the cost of resolution
·5 mins

Hello 👋

In this week’s newsletter I write about the 3 places to validate data contracts.

There’s also links to articles on engineering teams owning their own data, 3 rules for where AI doesn’t belong, and inventing work.


3 places to validate data contracts

I often get asked where to validate records against the data contract, and really there are 3 places you can do so, with the primary difference being the cost of resolution.

  1. Downstream
  2. In the platform
  3. Upstream
Hand-drawn diagram of a data pipeline with a "Data Contract" document at the top and dashed orange arrows pointing down to three stages: "Libraries" to a "Producer service" box with a terminal icon labelled "Upstream with a library"; "Schemas" to a message queue and database labelled "In the platform"; and "Data quality checks" to a group of connected boxes labelled "Downstream in the data pipeline". Black arrows link the stages from left to right, and a red arrow along the bottom labelled "Cost of resolution" points right.

Let’s go through each in turn.

1. Downstream

This is where you validate records against the data contract by using data quality checks in your data pipelines.

The cost of catching invalid records here is high. The record has already been emitted from the source system and likely written to many destinations, and therefore might now need to be fixed in many places.

It may also have been some time since the issue was introduced. This means even if you run your data quality checks regularly there could already be many records affected.

You also need to work out a process to resolve this issue with the data producer. However, given how far removed they are from your pipelines, and how much time might have passed from the commit that introduced the issue to the time you notify them, it may be too difficult or too late to revert the change in the upstream system, leaving you no option but to work around the problem by “fixing” it in your pipeline (COALESCE(...), CASE WHEN ..., etc).

2. In the platform

Depending on your architecture you may also be able to do some validation at the platform layer.

For example, if you’re using an event platform like Google Pub/Sub that supports schemas, or Kafka with its schema registry¹, you can provide a schema based on the data contract in a format such as Protobuf, Avro, or JSONSchema, and the platform will use that to validate each record before it accepts it.

If the validation fails, an error is returned to the sender, who can then handle it as they choose. This means incorrect data doesn’t leave the producer until the issue is resolved, reducing the cost of resolution compared to validation in the data pipelines.

However, depending on the schema format supported, the validation might be quite limited. For example with Protobuf and Avro it’s mostly just the schema and data types, while with JSONSchema you can do some more data quality checks based on the value of the field.

3. Upstream

Finally you can validate records upstream, in the source system. This can be done by providing libraries for the producer to use to send records to your data platform.

Often these are just thin wrappers around the SDK for the platform, for example around the Kafka SDKs, but since you own the code you can read in the full data contract and validate any checks you may have. This means you can go beyond what the platform itself can provide, catching a larger array of errors and preventing them from being written to other systems.

Again, the error is returned to the calling code, which can then handle it as it chooses.

However, it takes time to build and maintain these libraries, particularly if you have many different producers with different tech stacks. There’s also nothing forcing the use of these libraries, which is why you still need to work on the producers’ incentives.

Which to choose?

These solutions are complementary, rather than either/or. For example, implementing at the platform layer is easy to do if you have the right architecture, so there’s little reason not to do it there and combine that with checks downstream and/or upstream.

Ultimately though, it comes down to the cost of resolution. Handling downstream is the most expensive, while upstream is the cheapest to resolve. So if you can only focus on one, it’s best to look upstream.

And if you’re looking for a nice way to articulate the cost of resolution, check out the 1:10:100 rule of data quality.

¹ In Kafka this is actually validated in the producer’s serialiser, not in the platform. But the effect is the same.


Why Engineering Teams Need to Own Their Data by Xavier Gumara Rigol

Good discussion on how to shift data ownership left to engineering teams.

**When You Have a Hammer: Three Rules for Where AI Doesn’t Belong by Julia Bardmesser (on LinkedIn)**

I particularly like this one on meeting summaries:

> Whoever writes the narrative shapes the outcome. They decide which action items go at the top, which ones sink to the bottom, and how the decisions are framed for the people who weren’t in the room.

A Staff Engineer’s Guide to Inventing Work by Sujith Jay Nair

Good advice for anyone working in a (data) platform team.


Being punny 😅

Fact of the Day: John Lennon wrote “Love me do” after a visit to the hairdressers.


Thanks! If you’d like to support my work…

Thanks for reading this weeks newsletter — always appreciated!

If you’d like to support my work consider buying my book, Driving Data Quality with Data Contracts, or if you have it already please leave a review on Amazon.

Enjoy your weekend.

Andrew


Want great, practical advice on implementing data mesh, data products and data contracts?

In my weekly newsletter I share with you an original post and links to what's new and cool in the world of data mesh, data products, and data contracts.

I also include a little pun, because why not? 😅

    (Don’t worry—I hate spam, too, and I’ll NEVER share your email address with anyone!)


    Andrew Jones
    Author
    Andrew Jones
    I build data platforms that reduce risk and drive revenue.