Video in progress

Strong Middle 🧩 Microservices

When you change an event schema, what do you watch for so old and new consumers don't break?

Events live a long time and consumers are updated at different times, so schema changes must follow compatibility rules. Schema Registry checks the compatibility type (BACKWARD, FORWARD, FULL) and doesn't let a breaking change be written by the producer.

📖 Answer

The difference from REST: a Kafka topic still holds messages from a week ago. If a new consumer replays, it must be able to read the old format. And an old consumer may not be updated yet and must read the new format.

The compatibility types (in Confluent Schema Registry terms):

  • BACKWARD: a consumer with the new schema can read old messages. Allowed: removing a field, adding a field with a default value. Consumers are updated first.
  • FORWARD: a consumer with the old schema can read new messages. The producer is updated first.
  • FULL: both. Only adding and removing optional fields with defaults.

A new field in Avro:

{"name": "discountCode", "type": ["null", "string"], "default": null}

Without a default, the BACKWARD check fails and the registry rejects the schema. That's good: the error lands in CI, not on prod.

With JSON the same rules apply, only nobody checks them automatically. In that case, at least: the consumer ignores unknown fields, you never change a field's name or type, and a consumer doesn't crash when a new value shows up in an enum.

If you truly need a breaking change, I create a new event type or a new topic (order-events.v2) and write to both for a while, then delete the old one once the consumers have moved.