Versioning proto files
Any API is supposed to evolve and when a formal contract is defined between a client and a server, such as a .proto
file intends to do, we need to be very careful when designing the structure of every message. Once a message is serialized, the only way to unmarshall the binary payload is to know the exact strategy used for constructing this bit sequence.
In the next sections we’ll explain the approach of protobuf for serializing every type of data so that we’ll fully understand the why and the how of the following tips:
- What happens with the deprecated fields? The tip is to create all fields as
optional
. Proto version 3 has adopted the optional statement by default when defining fields. This will avoid future deprecations to raise errors. - What happens with the new fields? The tip is to add them always at the end. Replacing old tags should be forbidden, so the association of a field with its tag number should always remain the same.