Search code examples
serializationdeserializationprotocol-buffersbinary-serializationprotobuf-java

Does removing existing field from protobuf message cause issues?


I am having one protobuf message -

message Sample{
    string field1 = 1;
    string field2 = 2;
    string field3 = 3;
}

These messages are stored in datastore in binary format. So if I want to remove any of the defined field in the above message will it cause any issue in deserialization of the message from datastore?


Solution

  • No. Removing fields is fine, although you might want to mark it reserved so that nobody reuses it in an incompatible way. New code with old data (with the field) will silently ignore it; old code with new data will just load without the field populated, since everything in proto3 is implicitly optional. This was more of a problem in proto2, when required was a thing. Another option is to leave the field but mark it with [deprecated = true] - it'll still exist and be populated, but some tools will mark the member with the platform-specific obsolete markers for that language/framework.