gRPC, real-time APIs and webhooks · mid
Changing a proto without breaking old clients
Protobuf puts field numbers and wire types on the wire, not names. You may add fields with new numbers, and you must never reuse, renumber or change the type of an existing field.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- The wire format carries field numbers and wire types. Names are only for humans and generated code.
- Moving items from field 5 to field 4 is breaking: old readers take field 4 as another type, such as the coupon string, and read item bytes as text.
- Reusing a field number for a new meaning is breaking. When you remove a field, mark its number and name as reserved so nobody reuses it.
- Changing string to enum changes the wire type (length-delimited to varint), so old and new cannot read each other. Add a new field instead and fill both for a while.
- int32 to int64 is wire-compatible, but old readers silently cut values that do not fit in 32 bits. For money in paise this can corrupt large amounts.
- Safe: add a field with a new number, add an enum value (old code must handle an unknown value), add a new rpc method.
- Unknown fields are kept or skipped by readers, which is why old clients survive new fields. Never rely on the default value to mean missing in proto3 for plain scalars; use optional or a wrapper.
The red pen
Common traps: mistake → fix
Mistake: Renaming a field is breaking
Fix: Names are not on the wire, so renaming is safe for binary Protobuf. It does break JSON mapping and generated code.
Mistake: int32 to int64 is always safe because both are numbers
Fix: Old readers truncate large values silently.
Mistake: I can reuse a deleted field number after a few months
Fix: Old data and old clients still exist. Reserve the number forever.
Easy to hard
Questions interviewers ask, easy to hard
- What goes on the wire in Protobuf: field names or field numbers?
- Which proto changes are safe and which are breaking?
- Why is int32 to int64 risky even though it is wire-compatible?
- What does reserved do and when do you use it?
- Given a diff of a proto file, say which changes will break old clients and give the safe version of each.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.