Kafka message versioning: version fields, versioned topics and Schema Registry
Codemia Knowledge Hub ·
There are three common ways to version the message format on a Kafka topic: put a version number in each message, publish each version to its own topic, or manage schemas centrally with a schema registry. All three exist for the same reason: producers and consumers in a distributed system are updated at different times, so schema changes have to stay compatible.
Why message formats need versioning
A Kafka topic is a category or feed name that records are published to, and topics are multi-subscriber. As systems evolve, the structure of the messages sent to a topic changes: fields are added, old fields are removed, or a field's data type changes. Those changes must be managed so that every producer and consumer can still work with the data.
The strategies:
- Single topic with version number: include a version number in the message so consumers can adapt their processing.
- Multiple topics: use different topics for different message versions.
- Schema registry: manage and enforce schemas across all messages from a central registry.
A version number in the payload
Each message carries metadata about its version, and consumers read it to decide how to process the message.
Example
A JSON message:
Consumers branch on the version field:
The consumer has to handle every version it may receive, which takes care.
A separate topic per version
Create one topic per schema version. For instance, user_updates_v1 carries version 1 messages and user_updates_v2 carries version 2.
Trade-offs
| Aspect | Advantages | Disadvantages |
| Consumer Simplicity | Easier for consumers as they process a consistent message format per topic. Decouples version handling from business logic. | Requires more management overhead to handle multiple topics. May lead to duplication of consuming logic across services. |
| Producer Management | Clear segregation of message versions at the source level. | Increases complexity in managing topic lifecycle and partitioning. |
A schema registry
A schema registry is a central repository for storing and retrieving message schemas and enforcing a standard schema across all messages. The most common implementation is the Confluent Schema Registry.
Workflow with a schema registry
- Define the schema: create an Avro schema for your messages.
- Register it: upload the schema to the registry.
- Produce: serialize data with the schema when sending messages.
- Consume: consumers use the same schema to deserialize and process messages.
Choosing a strategy
Embedding a version in each message gives immediate flexibility. Separate topics give better isolation and simpler consumer logic. A schema registry is the most robust, centralized way to manage schema evolution. Each fits different scenarios.
Related reading
- Kafka topic no longer exists after restart
- Kafka topic partition and Spark executor mapping
- Kafka topic partitions
- Kafka topic partitions to Spark streaming
- Kafka topic per producer
- Kafka Topic vs Partition topic
- Kafka transaction failed but commits offset anyway
- Kafka transactionLog fails with NotEnoughReplicasException, despite correct config
System design interview problems on this topic
- Design a Distributed Messaging System: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Webhook Notification Service: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.