Q&A-2Define a producer data contract and validate it at ingestion.
Answer
The 90-second answer. A producer data contract is a versioned, machine-readable agreement about what a producer puts on the wire and what it promises about it. Validation at ingestion is where those promises get enforced before the data becomes trusted. I'd assume Kafka as transport, a schema registry, and a consumer that owns the landing table: say Iceberg or Delta. The contract covers three things: identity and schema, time and completeness, and semantics. Validation runs in three stages (envelope, schema, business invariants) and anything that fails goes to quarantine with its raw bytes intact. Never coerce a value to make it pass.
A contract that's actually enforceable looks like this:
contract: orders.events
version: 3
owner: payments-platform
producer: checkout-service
schema: registry subject orders.events-value, Avro, compat BACKWARD
key: order_id
required: [order_id, amount, currency, occurred_at]
event_time: occurred_at, UTC, max_lag 15m
completeness: kafka offset per partition, EOF marker per partition
volume: 8k-12k records/min
pii: email -> tokenized at sourcecompat: BACKWARD is the Confluent Schema Registry mode that lets consumers upgrade before producers. Adding an Avro field with a default is backward compatible; removing one without a default is not. In Protobuf, deleting a field number and reusing it breaks the wire format: reserve it instead. In JSON Schema, additionalProperties: false makes every new producer field a breaking change, which is usually the wrong default for a contract you want to evolve.
Worked trace (hypothetical, one 1-minute micro-batch):
| stage | check | in | rejected | example error |
|---|---|---|---|---|
| 1 | envelope: schema_id present, producer identity matches topic ACL | 10,000 | 3 | missing schema_id |
| 2 | decode against orders.events v3 | 9,997 | 12 | currency not in ISO-4217 enum |
| 3 | invariants: amount > 0, occurred_at <= ingest_at, order_id non-null | 9,985 | 22 | amount = -1 |
| land | 9,963 |
37 rejected out of 10,000 is a 0.37% rejection rate. I'd alert at 0.5% sustained over five minutes, and separately alert if the rate drops to exactly zero after a parser deploy: that usually means the validator stopped running, not that the producer got perfect.
Trade-offs, and when the choice flips. Validate at write (producer-side, in CI plus at produce time) versus validate at read. Write-side catches drift before it lands and costs the producer latency; read-side keeps the producer decoupled but lets bad data sit in the lake. Flip to read-side when the producer is a third party you can't put a validator in front of. Quarantine versus reject-the-batch: quarantine keeps the pipeline moving but silently loses data if nobody watches the quarantine topic; reject-batch preserves atomicity but stalls. Flip to reject-batch for a financial ledger, quarantine for clickstream. Compatibility mode flips the same way: BACKWARD when consumers deploy first, FORWARD when producers do, FULL when you control neither, NONE only for a topic with one tightly-coupled producer and consumer.
Failure modes and how you see them. Silent coercion ("12" parsed to 12, or a timestamp read in local time) shows up as a rejection rate that collapses after a parser change. An early EOF marker makes downstream aggregates undercount; detect it by comparing marker count to partition count. Duplicate order_id after a producer restart slips past idempotent-producer dedup, which only covers a single producer session; detect with a key-dedupe window at landing. A producer bypassing the registry and writing raw bytes shows up as a schema_id histogram that doesn't match the subject's current version.
Finally, authenticate producers, mTLS or SASL/SCRAM plus per-topic ACLs, and carry tenant identity inside the signed envelope so one tenant can't declare another's schema or identity. Record contract version, validator version, and accepted/rejected counts per batch, and give the producer a feedback channel plus a replay path from quarantine.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.