Using Schema Registry
1. Understanding Schema Registry Role
| Aspect | Description | Detail |
|---|---|---|
| Central Store | Versioned schemas | Avro/Protobuf/JSON |
| Schema ID | Embedded in message | 5-byte prefix |
| Compatibility | Enforce evolution rules | Safe changes |
2. Installing Schema Registry
| Step | Description | Detail |
|---|---|---|
| Package | Confluent Platform | schema-registry |
| Backing Store | _schemas topic | Compacted |
| Port | HTTP 8081 | Default |
3. Configuring Schema Registry URL
| Config | Description | Detail |
|---|---|---|
| schema.registry.url | Client → registry | Required |
| Serializer | KafkaAvroSerializer | Auto-register |
| Multiple | Comma list for HA | Failover |
Example: Client config
props.put("value.serializer",
"io.confluent.kafka.serializers.KafkaAvroSerializer");
props.put("schema.registry.url", "http://localhost:8081");
4. Registering Schemas
| Aspect | Description | Detail |
|---|---|---|
| Auto | Serializer registers | On first send |
| Manual | POST to subject | REST API |
| Subject | topic-value / topic-key | Naming strategy |
Example: Register schema
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schema":"{\"type\":\"string\"}"}' \
http://localhost:8081/subjects/orders-value/versions
5. Retrieving Schemas
| Endpoint | Description | Detail |
|---|---|---|
| /schemas/ids/{id} | By global ID | Raw schema |
| /subjects/{s}/ versions/{v} |
By subject+version | latest allowed |
| latest | Most recent version | Convenience |
6. Listing Subjects
| Endpoint | Description | Detail |
|---|---|---|
| /subjects | All registered subjects | Array |
| /subjects/{s}/ versions |
Version list | Per subject |
| ?deleted=true | Include soft-deleted | History |
7. Deleting Schema Versions
| Type | Description | Detail |
|---|---|---|
| Soft Delete | Mark deleted | Recoverable |
| Hard Delete | ?permanent=true | Irreversible |
| Scope | Version or whole subject | Granular |
Warning: Permanent deletes are irreversible and can break consumers still reading old data.
8. Setting Compatibility Mode
| Mode | Description | Detail |
|---|---|---|
| BACKWARD | New reads old | Default |
| FORWARD | Old reads new | Producer-first |
| FULL | Both directions | Strict |
Example: Set subject compatibility
curl -X PUT -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"compatibility":"FULL"}' \
http://localhost:8081/config/orders-value
9. Checking Compatibility
| Endpoint | Description | Detail |
|---|---|---|
| /compatibility/ subjects/{s}/... |
Test new schema | No register |
| is_compatible | Boolean result | true/false |
| CI Gate | Validate before deploy | Safety |
Example: Check compatibility
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data @new-schema.json \
http://localhost:8081/compatibility/subjects/orders-value/versions/latest
10. Exporting Schemas
| Aspect | Description | Detail |
|---|---|---|
| Backup | Dump all subjects | Disaster recovery |
| Exporter | Schema Linking | Cross-cluster |
| _schemas Topic | Mirror for backup | Source of truth |