Schema Registry centralizes and versions schemas for messaging systems. Compatibility checks ensure safe evolution without breaking changes.
Schema Registry in Kafka¶
Centralizes and versions schemas, enforces compatibility.
Avro Schema¶
{
"type": "record",
"name": "Order",
"namespace": "cz.core.events",
"fields": [
{"name": "order_id", "type": "string"},
{"name": "total_czk", "type": {"type": "bytes", "logicalType": "decimal", "precision": 12, "scale": 2}},
{"name": "status", "type": {"type": "enum", "name": "Status", "symbols": ["PENDING", "CONFIRMED", "SHIPPED"]}},
{"name": "notes", "type": ["null", "string"], "default": null}
]
}
Compatibility Modes¶
- BACKWARD — new consumer, old producer
- FORWARD — old consumer, new producer
- FULL — both (safest)
from confluent_kafka.schema_registry import SchemaRegistryClient
from confluent_kafka.schema_registry.avro import AvroSerializer
registry = SchemaRegistryClient({'url': 'http://registry:8081'})
serializer = AvroSerializer(registry, schema_str)
producer.produce('orders', value=serializer(order, ctx))
Summary¶
Schema Registry is essential for production Kafka. Versioning and compatibility checks prevent runtime errors.
schema registryavrokafkaserialization