Consider a Kafka topic using Avro serialization with schema evolution enabled. The producer adds a new optional field to the schema. The consumer uses the older schema without this new field. What happens when the consumer reads the message?
Producer schema v2: {"type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"age","type":["null","int"],"default":null}]}
Consumer schema v1: {"type":"record","name":"User","fields":[{"name":"name","type":"string"}]}Think about forward compatibility: can an older consumer read data produced with the newer schema?
Forward compatibility means new schemas can add optional fields with defaults. Older consumers ignore these new fields and read data successfully.
A Kafka consumer expects a schema with a new required field added (no default). The producer sends data using the older schema without this field. What is the result when the consumer tries to deserialize the message?
Producer schema v1: {"type":"record","name":"User","fields":[{"name":"name","type":"string"}]}
Consumer schema v2: {"type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"email","type":"string"}]}Consider backward compatibility and required fields without defaults.
Backward compatibility requires that new schemas can read old data. But if a new required field has no default, the consumer cannot fill it, causing a deserialization error.
In Kafka schema registry, which compatibility mode ensures that schemas are compatible both backward and forward?
Think about the mode that combines both backward and forward compatibility.
Full compatibility mode ensures that new schemas can read data produced by old schemas (backward) and old schemas can read data produced by new schemas (forward).
A Kafka topic uses Avro schemas. The original schema has fields 'name' and 'age' (both required). The new schema removes the 'age' field. What happens when the new schema is registered with full compatibility enabled?
Original schema: {"type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"age","type":"int"}]}
New schema: {"type":"record","name":"User","fields":[{"name":"name","type":"string"}]}Removing required fields breaks forward compatibility.
Removing a required field breaks forward compatibility because old consumers expect the 'age' field but new data produced with the new schema won't include it (and old schema has no default for it). Full compatibility requires backward and forward compatibility, so the registry rejects the new schema.
Given the original schema and a new schema, the new schema registration fails under backward compatibility. Identify the cause.
Original schema: {"type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"age","type":["null","int"],"default":null}]}
New schema: {"type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"age","type":"int"}]}Check changes in field defaults and types.
Backward compatibility requires that new schemas can read old data. Removing the default from a nullable field makes the new schema incompatible with old data that may have nulls.