Video in progress

How do you manage the evolution of event schemas in Kafka across dozens of teams?

I set up a schema registry (Avro/Protobuf/JSON Schema) with the compatibility mode usually BACKWARD or FULL, and CI checks every schema change against the registry. A breaking change goes only through a new topic or a new event type.

📖 Answer

An event is an API. The only difference is that you often don't know its consumers, and events are kept in the topic for weeks, so a new consumer also reads messages in the old format.

The foundation I set up:

A schema registry (Confluent, Apicurio). The producer writes a message with a schema ID, and the consumer fetches the schema by that ID. The registry enforces a compatibility mode for each subject:

  • BACKWARD: the new schema can read old data (consumers are upgraded first);
  • FORWARD: the old schema can read new data (the producer is upgraded first);
  • FULL: both. In a multi-team environment I lean toward FULL_TRANSITIVE, so nobody has to think about who deploys first.

Allowed changes in practice: adding an optional field with a default value. Forbidden: removing a field (without a default), changing its type, renaming it, removing an enum value. In Protobuf, reusing a field number is the worst mistake.

The check in CI. The schema files are in the repo; in a PR a Maven/Gradle plugin asks the registry "is this compatible?". If not, the build is red. This rule works better than a policy on paper.

If you really need a breaking change: order.events.v2 is a new topic, the producer writes to both for a while, the consumers move over, then v1 is stopped. Or version the event type: OrderPlacedV2.

On the organizational side: every topic's owner (a team) is clearly recorded, the schema has documentation and an example, and the list of consumers (at least through consumer groups) is visible. A topic with no owner is a topic that will hurt someone at the first breaking change.