Skip to content

Event contracts and changes

Schema evolution and compatibility

Check who can read old and new records, and whether the results keep their meaning.

Learn with an AI assistant

Copy the prompt and paste it into a chat with an AI assistant.

You are a tutor for the course "Stream Processing".
Topic: "Schema evolution and compatibility"
In short: Check who can read old and new records, and whether the results keep their meaning.
Topic text in Markdown: https://stream-processing-systems.github.io/contracts/schema-evolution-and-compatibility.md
Base your explanations on the topic text. First ask how I want to study: a short summary, a step-by-step walkthrough, or a deep dive with questions that check my understanding. Use the text's example and terms. If you add anything the text does not say, point it out.

The team publishing charger readings wants to add firmware_version so the report can group power readings by firmware. The map still needs the same information about periods of use. The report’s new code will also reread last month’s log, when the feed did not send a firmware version.

The map, the report, and the feed can be updated on different days. Schema evolution is how the record structure changes over time. Compatibility tells us which versions of the records and readers can work together. Which combinations does the team need to check before it changes the feed?

The new report must read old records from the log. If the feed changes before the map is updated, the old map must also be able to read new records.

Written recordReaderWhat to check
OldNewBackward compatibility. Can the report read a record that has no firmware_version?
NewOldForward compatibility. Can the old map read a record that includes firmware_version?
NewNewDo the feed and the new report agree on how to use the new field?

The old map can ignore the new field if its decoder allows extra fields and its calculation needs only the original fields. A reader that rejects extra fields needs an update before it can accept the new records.

Apache Avro is a data format that defines how to read records when the writer and reader use different schemas. When their record schemas match, Avro ignores fields that appear only in the writer’s schema. For a field that appears only in the reader’s schema, Avro uses the reader’s default value. Reading fails if that field has no default.1

The report’s Avro schema can allow either a string or null for firmware_version and set the reader default to null. When the report reads a record written before the field was added, it puts that reading in the group with unknown firmware. For a newly written record, the writer still encodes the field. It can send null when it has no version to report.2

Adding a value to a list can also change what an old reader accepts. Suppose Avro schemas describe charger status as an enum, a fixed set of names. The feed adds paused for a connected car that has temporarily stopped drawing power. The updated map counts the charger as occupied during the pause, and the history shows that charging paused.

Under the Avro specification, the old reader uses the enum’s default value for paused if it has one. That default must already be a member of the old enum. With no default, reading paused fails.1 With a default of unknown, the map can show that availability is unknown.

Suppose a producer update puts 2.2 into power_w because it now measures power in kilowatts. Both Avro schemas give power_w the type double, which accepts fractional values. The new value passes the type check. The old report displays 2.2 watts when the intended value is 2,200 watts.

The producer can convert its measurement to watts before publishing it. If it needs to publish kilowatts directly, it can introduce a distinct field such as power_kw and keep writing power_w while old readers need it. A test that feeds in a 2.2 kW measurement and checks for 2,200 W in the report catches the error even when both schemas accept the number.

The team can first deploy readers that handle records both with and without firmware_version, then publish the new field. If some readers stay on the old version, the team also checks that they accept the new records. A rollout order follows from which combinations will be running.

For the new status, the team tries reading a record with paused using the decoder version each consumer runs. In Python Avro 1.12.0, the schema checker can accept the old enum with a default, while the decoder still rejects the record containing paused.34

A new reader may encounter several schema versions during replay. The team keeps the writer schemas needed to decode retained records. It tests a sample from each retained version, checking both decoding and the report it produces. That includes readings without a firmware version and any older statuses that the live feed no longer sends.

If a producer sends paused while an old map reader still rejects it, one record can hold up the readings behind it. That reader needs a policy for what to do at the rejected record’s position.

  • Check new readers against old records and old readers against new records whenever those combinations can occur.
  • Choose reader defaults that preserve what is known about old records.
  • Test decoding and the result with the deployed reader and the records it can encounter during rollout and replay.
  1. Apache Avro 1.12.0, Schema Resolution.

  2. Apache Avro 1.12.0, Records.

  3. Apache Avro 1.12.0, compatibility checker for Python enums.

  4. Apache Avro 1.12.0, Python enum decoder.

© 2026 Grig Alex · CC BY-NC-SA 4.0