Choose a serializer
Configure them like any other serializer, plus the registry URL and credentials:
Subject name strategies
The serializer derives the subject name from the record. Three strategies ship with the Confluent clients:
Set it per producer:
Multiple event types on one topic
To put several record types on a single topic, useRecordNameStrategy or
TopicRecordNameStrategy so each type gets its own subject and evolves on its own schedule. With the
default TopicNameStrategy all types share one subject, and the compatibility check compares
unrelated schemas against each other.
Protobuf handles this most naturally through a oneof wrapper message; in Avro you’d use a union at
the top level.
Auto-registration
By default a producer registers its schema the first time it sends a record under a subject that doesn’t have it. That’s convenient in development and risky in production—any application can create a subject and set its first version. Turn it off, and register schemas deliberately instead:auto.register.schemas off, the serializer looks the schema up and fails if it isn’t
registered. With use.latest.version on, it uses the subject’s latest registered version rather than
the schema derived from your class.
Restrict who can register schemas with the schema-writer and schema-reader
roles.
Normalization
Two schemas that differ only in field ordering or whitespace are semantically identical but produce different schema IDs. Normalization canonicalizes a schema before it’s stored or looked up, so cosmetic differences stop creating new versions. Request it with?normalize=true on registration and lookup, or set
AbstractKafkaSchemaSerDeConfig.NORMALIZE_SCHEMAS on the client.
The wire format
The serializer prefixes every record:Client caching
Deserializers cache schemas by ID, so a consumer hits the registry once per distinct schema rather than once per record. Producers cache the subject-to-ID mapping the same way. Because of that cache, a schema registered moments ago may not be visible to a client that already cached a lookup miss. Restart the client, or configure a cache expiry, if you’re chasing an unexpectedSchema not found.
Next steps
Schema references
Compose schemas instead of duplicating shared types.
Evolution and compatibility
What each compatibility mode permits.