Handling schema evolution in Kafka with Avro.
Instruction: Describe strategies for managing schema evolution in Kafka when using Avro, ensuring compatibility across versions.
Updated
Official answer
Avro resolves a writer schema against a reader schema. Registry policies such as BACKWARD, FORWARD and FULL are compatibility checks built around format rules; they are not Kafka broker settings. Decide whether checks must cover the previous version or every retained historical version.
Consider a record named Reading whose first version contains only an integer value. A second version adds a string unit with default "unknown". The new reader can read old bytes and supply "unknown": backward compatibility. The old reader can read new bytes and ignore unit: forward compatibility. Removing the default from the new reader breaks old-to-new reading because old bytes have no unit field. A default is a resolution value, not permission to omit an arbitrary field from the data supplied to every writer API.
Nullable and defaulted are different properties. A union of null and string accepts either value; a null default lets a new reader fill a missing field if the union permits null. Renames require careful alias support and direction testing, and numeric promotions are directional: an int writer can resolve to a long reader, while a long writer does not generally resolve to an int reader.
For a backward-only rollout, deploy readers capable of old and new data before enabling new writers. Preserve writer-schema references, test real bytes in both directions and exercise retained history and state-store recovery. Structural compatibility cannot detect a unit change from degrees Celsius to Fahrenheit; document and test semantic meaning separately.
Avro resolution and defaults, registry policies and rollout order