📨 Apache Kafka Intermediate

How do you handle schema evolution in Kafka?

Answer

Schema evolution — changing the message format of a Kafka topic — without breaking producers or consumers. The Schema Registry enforces compatibility rules: Backward compatible: new schema can read data written by old schema. Safe for consumer upgrades first (add optional fields with defaults). Forward compatible: old schema can read data written by new schema. Safe for producer upgrades first (remove fields, add fields without defaults). Full compatible: both backward and forward. None: no compatibility check. Rules for safe Avro evolution: adding a field with a default value is backward AND forward compatible. Removing a required field breaks both. For Protobuf, adding fields with new field numbers is safe. Best practice: upgrade consumers before producers for backward-compatible changes. Use the FULL_TRANSITIVE compatibility mode for the strictest safety in high-traffic shared topics.