Overview
Curated: · Written: · Reviewed:
Schema Evolution & Versioning
In one line
Change a shared schema so every producer, stored record and consumer that depends on it keeps decoding correctly. Pick a compatibility direction and a deployment order that make that true. Reach for it whenever a record, topic, table or API outlives a single deploy.
Key definitions
- Backward compatible: a new reader decodes old data. Upgrade consumers first.
- Forward compatible: an old reader decodes new data. Upgrade producers first.
- Full: both directions hold.
- Writer schema vs reader schema: Avro resolves the schema the data was written with against the schema the reader asks for. Fields match by name or alias, reader defaults fill gaps, and writer-only fields are skipped.
- Field identity: Protobuf tag numbers and Iceberg field IDs identify fields. Names do not.
- Expand-migrate-contract: add the new representation beside the old, dual-write and backfill, then remove the old one after telemetry confirms no readers need it and the rollback window has passed.
How it works
- The producer serializes with a schema ID. The registry checks the new version against the subject's policy and returns HTTP 409 on failure.
- An Avro reader matches each reader field to the writer schema by name or alias. A missing field with a default takes the default. A missing field without one fails the read.
- Protobuf matches fields by tag number on the wire. JSON mappings use field names, so a rename changes the JSON key and the generated API while the bytes stay valid.
- Iceberg and Delta map columns by field ID or column mapping, not by name, so a rename keeps the data readable.
When to use and when not to
| Situation | Choice | Why |
|---|---|---|
| Public stream, unknown consumers | BACKWARD_TRANSITIVE; breaking change moves to a new topic version | Every retained version must still decode |
| Internal stream, co-deployed consumers | BACKWARD against versions still in the replay window | The check matches what is actually alive |
| Owned Iceberg or Delta table | Additive change under the engine's rules | Field IDs keep renames safe |
| Meaning, unit or grain changes | New field or new version, even if the type is unchanged | The registry cannot see meaning |
| Old readers need a removed field | Do not remove; deprecate and expand-contract | Removal breaks readers you cannot see |
| FULL_TRANSITIVE on a high-churn subject | Avoid | Teams end up disabling the check, which is worse |
Traps interviewers probe
- Adding a field without a default under BACKWARD. The registry rejects it because an old record has nothing to fill the field. Fix: add a truthful default. A nullable union alone is not a default.
- Treating registry acceptance as runtime safety. FORWARD accepts an added field with no default, but v2 readers then fail on v1 records. Fix: deploy in the order the direction requires, and replay historical records through the new reader.
- Renaming an Avro field without an alias. The reader substitutes the default and no error is raised. Fix: add the alias on the reader field, or use expand-contract.
- Reusing a deleted Protobuf tag. Old and new int32 fields share a wire type, so the value is decoded into the wrong field without error. Fix: reserve the tag number and name.
- Passing structural checks with a semantic change. Milliseconds becoming seconds passes every type check and corrupts decisions. Fix: encode the unit in the field name and add a contract test against the product's valid range.
Interview tips
Open with the direction, the format and the consumers you verified: "Backward against the retained versions in Avro, with the readers deployed first." Then state whether the change is additive.
Expect these follow-ups:
- Who may disable a compatibility check, and what does the audit trail show?
- How do you know it is safe? Old writer with new reader, new writer with old reader, oldest stored data replayed, and the registry outage case.
- How long can you roll back? For tables, the window is bounded by snapshot retention, because old snapshots and time-travel queries still read the old schema.
- What happens to records written several versions ago? They must still decode under the current reader.
30-second outline:
- Name the format and the direction.
- State the change and whether it is additive, with its default.
- Give the deployment order that makes the direction true.
- Name the test: historical fixtures through the real client versions.
- Name the semantic check and the rollback path.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.