Apache Avro: manage data compatibility with writer and reader schemas
Apache Avro 1.12.0 defines record structure and types with schemas and serializes data in binary or JSON form. Avro binary data does not contain field names or type metadata, so compatibility depends on how the writer schema used to create data is matched with the reader schema expected by a consumer. Preserve the writer schema with stored data or make it reliably retrievable.
Apache Avro 1.12.0 defines record structure and types with schemas and serializes data in binary or JSON form. Avro binary data does not contain field names or type metadata, so compatibility depends on how the writer schema used to create data is matched with the reader schema expected by a consumer. Preserve the writer schema with stored data or make it reliably retrievable.
Writer and reader schemas
The writer schema describes how data was written; the reader schema describes what the consumer expects. Matching schemas read directly. Different versions can also resolve under Avro's rules when names and types are compatible. Record fields match by name. A reader may ignore fields present only in the writer schema. If the reader schema adds a field, its default can supply a value when that field is absent from writer data; without a default, reading may fail.
A field default is not permission for the writer to omit the field. It is used by the reader during schema resolution when writer data lacks that field. Check field presence and default behavior separately.
Why binary data needs its schema
Avro binary encoding does not carry field names or the type of each byte. The schema specifies field order and value encoding. Files or systems must therefore retain the writer schema, or provide a way to retrieve it. Avro object container files store schema metadata. A message broker or custom protocol may instead define its own schema-ID lookup contract; a vendor-specific ID prefix is not part of Avro itself.
Avro also defines JSON encoding. It can be easier to inspect, but Avro JSON is not always interpreted like an ordinary JSON object. The Avro schema still matters, especially for types and unions.
Before deploying a schema change
Preserve the writer schema with data or define how consumers identify and retrieve it.
Test old data with the new reader and new data with old readers; compatibility direction can depend on rollout order.
Check whether new reader fields need defaults. A default does not mean writers always omit that field.
Review aliases for renamed fields and verify type promotions or union changes in the actual library.
Test representative historical data and handle failures as recoverable errors before rollout.
Pin and verify the Avro version, language library, registry configuration, and compatibility policy.
A schema file alone does not define message transport, authentication, retries, or registry policy. Avro defines encoding and schema resolution; envelopes and schema lookup follow the surrounding system contract.
Sources
[Apache Avro 1.12.0 Specification](https://avro.apache.org/docs/1.12.0/specification/)
[Apache Avro 1.12.0 Documentation](https://avro.apache.org/docs/1.12.0/)