A key Schema Registry feature is the ability to version schemas as they evolve. Compatibility policies are created at the schema metadata level, and define evolution rules for each schema.
After a policy has been defined for a schema, any subsequent version updates must honor the schema’s original compatibility, otherwise you experience an error.
Compatibility of schemas can be configured with any of the below values:
- Backward Compatibility
- Indicates that new version of a schema would be compatible with earlier version of that schema. That means the data written from earlier version of the schema, can be deserialized with a new version of the schema.
- When you have a Backward Compatibility policy on your schema, you can evolve schemas by deleting portions, but you cannot add information. New fields can be added only if a default value is also provided for them.
- Forward Compatibility
- Indicates that an existing schema is compatible with subsequent versions of the schema. That means the data written from new version of the schema can still be read with old version of the schema.
- When you have a Forward Compatibility policy on your schema, you can evolve schemas by adding new information, but you cannot delete existing portions.
- Full Compatibility
- Indicates that a new version of the schema provides both backward and forward compatibilities.
- Indicates that no compatibility policy is in place.
Validation level limits the scope of the compatibility check when you add a new version of
the schema. It checks compatibility only against the latest version or all previous versions
based on the validation level value configured. Validation level only makes sense when
coupled with compatibility. When compatibility is set to
None then the
validation is also ignored.
SchemaMetadata.Builder builder = new SchemaMetadata.Builder("Blah") .type("avro") .schemaGroup("Kafka") .description("test") .compatibility(SchemaCompatibility.BACKWARD) .validationLevel(SchemaValidationLevel.ALL);
When using the Schema Registry UI, the validation level defaults to ALL.
Schemas are compatible across multiple versions, for example, with Backward Compatibility, data written with version 1 can be read with version 7 too. All is the default validation level.
There is no transient compatibility, only the latest version is used, for example, with Backward Compatibility, data written with version 1 can only be read with version 2, not with version 7.
Allowed schema changes for different compatibilities
|Compatibility types||Validation levels||Changes allowed||Check against which schemas||Upgrade first|
||All previous versions||Consumers|
||All previous versions||Producers|
||Last version||Any order|
||Compatibility checking disabled||Depends|