How it works
During a rolling deployment, old and new versions run side by side, and a log holds old records long after producers change. So a format change has to work across versions. Backward compatibility means new readers can read old data. Forward compatibility means old readers can read new data.
Encodings differ in how they support this. JSON repeats field names in every record, which is readable but larger, and nothing enforces its shape unless you add a validator, so a changed type surfaces at runtime in some consumer. Protobuf writes numeric field tags instead of names, and parsers skip tags they do not recognize, so adding a field is safe; reusing a retired tag makes old data decode as the wrong field. Avro writes no tags: a reader needs the writer’s schema, commonly fetched from a schema registry, and matches fields by name. A new field needs a default so new readers can read old records.
Rollout order follows from compatibility. Take an Avro record whose coupon field has no default, and remove it. A new reader skips coupon in old records, so the change is backward compatible. An old reader meeting a new record has no value for coupon and fails, so it is not forward compatible. Therefore upgrade consumers first, then producers. Ship the producer first and old consumers fail on the first new record. Rolling it back does not help, because those records stay in the log until retention expires. A change that is only forward compatible reverses the order.
A Protobuf event has a price field holding dollars as a float. Five teams read it, and the topic keeps 30 days of records. You want integer cents, and a teammate proposes changing the field’s type and units in place, keeping its tag. What do you do instead?
Add a price_cents field with a new tag. Producers write both, which is safe because old parsers skip the unknown tag. Consumers move to price_cents and fall back to price for records that lack it. Once every consumer has moved, producers stop writing price and its tag is marked reserved. Keep the fallback for 30 days, since retained records may carry only the old field.
Use this as a guide for self review; written answers are not graded.Keep in mind
- Backward compatible means new readers handle old data; forward compatible means old readers handle new data.
- A log keeps old records, so rolling back a producer does not undo what it wrote.
- Rollout order follows from which compatibility direction a change has.