Home » Evolving Protobuf Schemas Without Breaking Older Clients

Evolving Protobuf Schemas Without Breaking Older Clients

Two readers exchange differently shaped message strips while one field position is visibly retired.

A Protobuf schema can change while old clients remain deployed if both versions can still interpret the bytes they receive and preserve the behavior their callers rely on. Keep field numbers stable, reserve numbers when removing fields, and test ProtoJSON separately where it is part of the interface.

Preserve the meaning of a field number

Suppose an order message starts with these fields.

message Order {
  string id = 1;
  string memo = 2;
}

When memo is retired, reserve field 2 before introducing a different field. Reusing 2 for a different string could let an older reader accept the bytes and assign them the old meaning. Reusing it with another wire type can produce a different failure. Giving the new field a distinct number makes intent explicit in the wire format.

message Order {
  reserved 2;
  reserved "memo";
  string id = 1;
  string fulfillment_note = 3;
}

Proto3 language guide explains which changes to a message definition are wire-safe and which require coordinated rollout. Reserving the old name also prevents reuse of that name in the schema. It does not make an old JSON client adopt the new property automatically.

Check the four directions that matter

Record which old and new services write and read the message. An old writer sending to a new reader exercises default or missing-field behavior. A new writer talking to an old reader exercises unknown-field handling. Old-to-old and new-to-new provide controls. Assert a business value after decoding in each supported combination.

A relay needs a separate case. It may parse and reconstruct a message rather than forward bytes. Verify whether the new field survives the actual relay's library and representation. Rebuilding a message field by field can discard information an older binary parser would otherwise preserve. A conversion to JSON introduces a separate set of rules.

Follow field 3 through an older relay

We loaded the two Order definitions into separate descriptor pools in Python Protobuf 6.33.5. The old writer sent id A and memo x. The new writer sent id A and fulfillment_note ice. The first payload was 0a 01 41 12 01 78 in hex. The second was 0a 01 41 1a 03 69 63 65. In that second message, 1a starts length-delimited field 3 and 03 is the three-byte length of ice.

Fields visible through each reader’s schema
Writer Reader Visible application values
Old Old id = A, memo = x
Old New id = A
New Old id = A
New New id = A, fulfillment_note = ice

The old reader exposed only id on the new input. We serialized that parsed object and sent the bytes to the new reader. It recovered ice. We then built a fresh old Order, copied only id and serialized it. The new reader returned an empty string for fulfillment_note. A relay owner can use that last value as a release check. If downstream fulfillment requires the note, qualify each relay before enabling that writer. The official unknown fields guidance explains the binary preservation rule.

Plan for interpretable but incompatible data

Adding an enum value illustrates the gap. Binary decoding may succeed while a consumer still rejects the value in application logic or treats it as a default branch with unsafe consequences. Inspect the consumers that switch on the enum. Keep producers from emitting the new value until deployed readers can handle it or define a supported fallback.

Take the same approach with ProtoJSON. JSON names, enum strings and whether a parser accepts unknown properties can matter even if the binary message is safe. Test actual client settings, including strict parsing, and wait to enable new fields through JSON until that path is qualified.

Make the rollout test small and repeatable

Keep representative payloads from the old producer and a fixture generated by the new producer. Run them through the mixed-version paths you support. The fixture is a starting point for an API contract test that also asserts required fields, business fallbacks and relay behavior. Write down which producers may emit a new value, which readers can handle it, and how long old payloads remain in storage before removing a compatibility path.

You may also like