Avro schema versioning and schema evolution
Codemia Knowledge Hub ·
Avro schema versioning works through schema evolution: you change a schema in compatible ways (such as adding a field with a default), Avro's schema resolution reconciles the writer's and reader's schemas, and a registry such as Confluent Schema Registry keeps track of every version. Apache Avro is a data serialization system, widely used with Apache Hadoop, that uses a compact binary format and defines schemas in JSON.
Avro schema basics
Avro data is always serialized with its schema, which describes the structure of the binary data. Schemas are built from:
- Primitive types: null, boolean, int, long, float, double, bytes, string
- Complex types: records, enums, arrays, maps, unions and fixed
A simple schema for a user:
Compatibility types
Schema evolution means modifying a schema without breaking the applications that use it. Each message is paired with a schema so the reader can interpret it. Avro compatibility comes in four kinds:
- Backward: the new schema can read data written with previous schemas.
- Forward: data written with the new schema can be read by applications using previous schemas.
- Full: both backward and forward.
- None: no compatibility is guaranteed.
Compatibility is what keeps applications working as they read older or newer data.
Rules for changing a schema
- Evolve conservatively. Add optional fields with defaults, or new items to arrays and maps. Do not remove fields or change types in ways that break reading.
- Rely on Avro's schema resolution, which handles missing, extra or modified fields.
- Track every version. A registry such as Confluent Schema Registry stores and serves the different versions.
Example: adding an optional field
Original schema:
New schema with an optional phone field:
This change is backward compatible: when the new schema reads old data that has no phone field, Avro fills in the default null. Readers still on the old schema simply ignore the extra field in new data.
Versioning practices
| Practice | Description | Benefit |
| Consistent Naming | Maintain consistent naming conventions across all versions. | Prevents confusion and errors during data processing. |
| Semantic Versioning | Use semantic versioning for schemas. | Helps in tracking compatibility and understanding the impact of changes. |
| Schema Registry | Use a schema registry for storing and retrieving schemas. | Centralizes schema management and enhances compatibility checks. |
Related reading
- AWS DynamoDB and MapReduce in Java
- Best of breed indexing data structures for Extremely Large time-series
- Best practice for integrating Kafka and HBase
- Best way to join two (or more) kafka topics in KSQL emiting changes from all topics?
- BrokerNotAvailableError Could not find the leader Exception while Spark Streaming
- Bucket records based on time(kafka-hdfs-connector)
- Build stateful chain for different events and assign global ID in spark
- Can a model be created on Spark batch and use it in Spark streaming?
Course lessons on this
System design interview problems on this topic
- Design a Big Data Processing Pipeline: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Top-K Request Analysis System: 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.