Skip to content

Lesson 3 of 9 · 25m

Schema Evolution and Versioning Without a Flag Day

Evolve protobuf contracts through additive change, compatibility checks, dual-read transitions, and disciplined deprecation rather than panic versioning.

Teams often treat versioning as a branding exercise: v1, then v2 when the first design becomes embarrassing. In production, version bumps are expensive because clients lag. The cheapest version is the one you never need. Design evolution as a sequence of compatible steps, not a future migration meeting.

Additive change is usually safe

You can normally add:

new fields with new numbers
new RPCs
new enum values, if clients tolerate unknown values
new response data that clients may ignore

You cannot casually change field numbers, field types, semantic meaning, or remove fields clients still read. JSON transcoding adds another constraint: field names become public API too.

Breaking detection belongs in CI

Use buf or equivalent contract checks before merge:

buf breaking --against '.git#branch=main'   --path proto/billing/v1/billing.proto

This catches wire-breaking edits mechanically. It does not catch semantic breakage. Turning status = 3 from "paid" into "chargeback" passes wire checks and still ruins every downstream system.

Enum rollout is a two-sided problem

Old clients may reject unknown enum values even though protobuf preserves them. A safe rollout often looks like:

1. deploy producers that can read the new value but never emit it
2. deploy consumers that tolerate the new value
3. enable producers to emit it
4. remove fallback behavior after rollout completion

This is boring, slow, and exactly why production systems stay up.

Deprecate with evidence

Mark old fields and methods deprecated, then measure actual use:

string customer_email = 4 [deprecated = true];

Deprecation without telemetry is wishful thinking. Log which clients still send or require the field, using request metadata or client version headers where available. Remove only after the observed population is operationally zero, not merely after a date on a roadmap.

When v2 is justified

A new major version is justified when the resource model itself changes, ownership boundaries move, or compatibility would create dangerous ambiguity. It is not justified because field names feel inelegant. If you do create v2, run v1 and v2 side by side with a documented sunset, translation ownership, and client migration metrics.

Contracts include generated clients

Publishing proto files is not enough for many teams. Generated SDKs, validation helpers, examples, and compatibility notes are part of adoption. A technically correct schema with no usable client path will be forked badly by every consumer.

Field notes

  • Never change a field from scalar to repeated as a clever migration; clients read that as a different shape.
  • Treat comments documenting semantics as contract text, not decoration.
  • Keep compatibility test fixtures: serialized old requests should decode and behave predictably.
  • Unknown fields can be preserved on the wire in some implementations, but do not build business logic on accidental round-tripping.
  • Schema review is production design review. Invite the people who carry the pager.

Was this lesson helpful?

Sign in to rate