Stanislav
Stanislav

Reputation: 21

How can Confluent SchemaRegistry help ensuring the read (projection) Avro schema evolution?

SchemaRegistry helps with sharing the write Avro schema, which is used to encode a message, with the consumers that need the write schema to decode the received message. Another important feature is assisting the schema evolution.

Let's say a producer P defines a write Avro schema v1 that is stored under the logical schema S, a consumer C1 that defines a read (projection) schema v1 and another consumer C2 that defines its own read (projection) schema. The read schemas are not shared as they are used locally by Avro to translate messages from the writer schema into the reader schema.

Imagine the schema evolution without any breaking changes:

Now imagine some schema breaking changes:

The question is how can the SchemaRegistry come in handy to prevent any breaking changes on the consumer side? Note that the compatibility check of the read schema has to be done against all versions of the write schema.

There is an endpoint that allows checking the compatibility against the versions in the subject. The issue is that it uses the compatibility type that is set on the subject. The subject which contains versions of the write schema can not be used, because it is configured with FORWARD_TRANSITIVE compatibility type, but the read schema has to be backward compatible.

Creating another subject with the compatibility type BACKWARD_TRANSITIVE will not work, because a new version of the write schema with a forwards-compatible change (e.g. add a non-optional field) will fail to be stored in this subject.

One option that came to mind is to have some unit tests written using the CompatibilityChecker. It's an ugly solution because each consumer must hold locally all versions of the write schema. It's going to be a pain to sync all the consumers when the producer's schema changes.

Upvotes: 2

Views: 392

Answers (1)

Viorel Ghelbert
Viorel Ghelbert

Reputation: 166

Schema Registry lets us keep track of schemas that are currently in use, both by producers and consumers.

Creating another subject with the compatibility type BACKWARD_TRANSITIVE will not work, because a new version of the write schema with a forwards-compatible change (e.g. add a non-optional field) will fail to be stored in this subject.

You were very close. Indeed, adding a non-optional field to the write schema is forward-compatible, but not backward-compatible because you may have data already produced that don't have values for this field. But we don't apply the same changes both to the write and read schemas. This only works when the change is both forward and backward compatible (aka full compatibility), e.g., adding/removing optional fields. In our case, we'd have to add the new field as optional to the read schema.

You can push the write schema to this new subject initially, but from that point on it is a separate read schema, and it would have to evolve separately from the write schema.

You can apply whatever approach you're currently using for checking the write schema changes. For example, make each consumer push the schema it's about to use to a subject with a BACKWARD_TRANSITIVE compatibility type before being allowed to use it.

There's also Schema Registry Maven Plugin for use in a CI/CD environment.

An alternative would be to use a single subject with FULL_TRANSITIVE compatibility.

Upvotes: 0

Related Questions