Prerequisites
- A Kafka cluster, or a Pulsar cluster with the Kafka protocol enabled, on StreamNative Cloud.
- An API key for a service account with the
schema-managerrole, plus produce and consume permissions on the topic. - Java 17 or later and Maven, for the producer and consumer.
curlandjq.
Step 1: Create a topic
Step 2: Define and register a schema
Createpayment.avsc:
payments-value subject:
Step 3: Build a producer
Add the dependencies:Step 4: Consume the records
payment.avsc. It reads the schema ID from each record’s prefix and fetches
the schema from the registry—which is the whole point of the registry.
Step 5: Make an incompatible change
Add a required field with no default. Createpayment-v2-bad.avsc:
BACKWARD, which requires that a consumer on the new schema can read
data written under the old one. The five records you produced have no currency, and the new schema
gives the reader nothing to substitute—so the change is rejected.
Try to register it anyway:
Step 6: Fix it
Give the field a default. Createpayment-v2.avsc:
currency = "USD"—the default fills the gap. That
single word is the difference between a safe change and a broken pipeline.
Step 7: Change the compatibility mode
Sometimes you genuinely need a breaking change. Loosen the mode deliberately rather than working around the check:payment-v2-bad.avsc registers. Set the mode back when you’re done:
GET /config/payments-value reports the real value. The global GET /config always returns NONE
regardless of what’s set—see
Confluent API compatibility.Clean up
What to take away
- A schema ID travels in each record; the consumer resolves it from the registry rather than being told the schema out of band.
BACKWARD, the default, means new-schema consumers must be able to read old data—so upgrade consumers before producers.- Defaults are what make a field addition compatible in Avro.
- Test with
/compatibility/...in CI, so an incompatible change fails the build instead of the deploy.
Next steps
Evolution and compatibility
Every mode, and which side to upgrade first.
Manage schemas
A registration workflow that holds up in production.