Reputation: 11091
I have two micro services. First service encodes messages using google protobuf
(google docs) and sends to second one. Second one decodes this message and uses the data.
Now I need to add a field to this message object. If I do it at one side only will it break another side?
For example, if I add something to json
this will break nothing. Is it really the same with google protobuf
?
Upvotes: 11
Views: 15651
Reputation: 2293
Cited from Goole Protobuf documentation on extending the Protobuf from here:
- you must not change the tag numbers of any existing fields.
- you must not add or delete any required fields.
- you may delete optional or repeated fields.
- you may add new optional or repeated fields but you must use fresh tag numbers (i.e. tag numbers that were never used in this protocol buffer, not even by deleted fields).
In your case, if your change on one side did not violate any of the above rules, it will not break the other side.
Upvotes: 17
Reputation: 5221
From the docs (see here: https://developers.google.com/protocol-buffers/docs/overview):
You can add new fields to your message formats without breaking backwards-compatibility; old binaries simply ignore the new field when parsing. So if you have a communications protocol that uses protocol buffers as its data format, you can extend your protocol without having to worry about breaking existing code.
Upvotes: 9