The evolution rules
We saw multiple problems caused by the evolution of the proto file and it is important to keep these in mind. So, it is time to recapitulate and formulate rules on how to evolve schemas in Protobuf.
Here’s the list of rules that we should follow if we need to maintain backward and forward compatibility:
- Never remove a reserved statement. This probably goes without saying but reserved statements are here to protect us. Do not remove or modify them; otherwise, you will get undefined behaviors.
- Never modify a field tag. This will lead Protobuf to decode data into unknown fields between versions. This means you will not receive that data and get a default value.
- Avoid reusing a field tag. As we saw, this can cause problems such as integer overflow or other problems due to type conversion. It is better to just add a new field to deal with the new data. Remember that tags are encoded as varints.
- Always add a reserved tag when deleting a field...