Home/Learn/Apache Kafka/Schema Registry & Avro

Schema Registry & Avro

Intermediate
Fundamentals

Schema Registry centralises Avro/JSON/Protobuf schemas so producers and consumers share a contract. It prevents breaking changes from silently corrupting downstream consumers.

Overview

Producers register schemas and embed a schema ID in each message; consumers fetch the schema by ID and deserialise. Compatibility modes (BACKWARD, FORWARD, FULL) control which schema changes are allowed.

Avro + Schema Registry in Spring Boot

Configure schema.registry.url on producer and consumer. Use KafkaAvroSerializer / KafkaAvroDeserializer.

Spring Boot — Avro + Schema Registry
# application.properties
spring.kafka.producer.value-serializer=io.confluent.kafka.serializers.KafkaAvroSerializer
spring.kafka.producer.properties.schema.registry.url=http://schema-registry:8081
spring.kafka.consumer.value-deserializer=io.confluent.kafka.serializers.KafkaAvroDeserializer
spring.kafka.consumer.properties.schema.registry.url=http://schema-registry:8081
spring.kafka.consumer.properties.specific.avro.reader=true

Schema Compatibility Modes

BACKWARD: new schema reads old messages. FORWARD: old schema reads new messages. FULL: both directions. NONE: no checks.

Schema Registry API — set compatibility
curl -X PUT http://schema-registry:8081/config/orders-value \
  -H "Content-Type: application/vnd.schemaregistry.v1+json" \
  -d '{"compatibility": "BACKWARD"}'

Key Points to Remember

  • 1Schema Registry stores schemas centrally; each message embeds only a 5-byte schema ID
  • 2BACKWARD: consumers with old schema can still read new messages
  • 3Adding a field with a default is BACKWARD compatible; removing a required field is not
  • 4Subject naming: {topic}-key and {topic}-value
  • 5Avro is compact binary; Protobuf has better language support; JSON is human-readable

Interview Questions

Sign in to ask Aria
1

What problem does Schema Registry solve in a Kafka-based system?

EasyConfluent
2

What is BACKWARD schema compatibility and which type of schema change breaks it?

MediumAmazon
3

How does Schema Registry avoid embedding the full Avro schema in every message?

MediumLinkedIn
4

What happens if a consumer has an older schema version and receives a message produced with a newer schema?

HardNetflix
5

When would you choose Protobuf over Avro for Kafka messages?

HardUber

Ask Aria about Schema Registry & Avro

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…