Video in progress

Strong Middle 📨 Kafka and messaging

Why do you need a Schema Registry, and what do backward compatibility rules forbid in schema evolution?

Schema Registry stores Avro/Protobuf/JSON schemas centrally; only a small schema ID travels in the message. When a new version is registered, compatibility is checked: in BACKWARD mode, a new consumer must be able to read old messages.

📖 Answer

When you send free-form JSON, one day a producer renames a field and three consumers break silently. The registry makes this contract enforceable: an incompatible schema simply can't be registered, and the producer gets an error.

Message format: 1 magic byte + 4 bytes of schema ID + payload. The consumer fetches the schema from the registry by ID and caches it.

Under BACKWARD (the Confluent default), for Avro:

  • adding a new field with a default value: allowed;
  • removing a field: allowed;
  • adding a required field without a default: not allowed, old messages don't have it;
  • changing a field type to an incompatible one (string → int): not allowed;
  • renaming: only with aliases.
{"name": "currency", "type": "string", "default": "UZS"}

When choosing a mode, think about deploy order: BACKWARD means you upgrade consumers first; FORWARD, the producer first; FULL, either order. Many teams pick BACKWARD_TRANSITIVE, because a topic can hold messages from several versions back.

Checking the schema against the registry in CI (with the Maven/Gradle plugin) catches breakage before prod.