Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Maintain Proto Files?

I've created 3 proto files and would like to keep it in a git repo:

enter image description here

separated from all others files. The repository contains only .proto files. I have 3 microservices and each of them has their own repository that is using those proto files to communicate with each others:

enter image description here

You can see on the picture above, that proto files are consuming from different microservices.

Assume, I am going to change the Protofile2 and push the changes to proto repository, remember proto files repository are separated from microservices repository:

enter image description here

When I run go test on service1 or service2, it should tell me, that Protofile2 has changed or does not have the same hash like proto file in the service2 folder:
enter image description here

That I have to generate the code again.

Does it exist any tools to solve the problem? Or how should I solve it?

like image 941
softshipper Avatar asked Feb 29 '20 10:02

softshipper


1 Answers

Here's what I suggest:

  • Store your protos (and their go generating makefiles) in a single git repo. Each definition should be in their own directory for import simplicity
  • tag the repo with a version - especially on potentially breaking changes
  • import a particular proto defs from your micro-services e.g. import "github.com/me/myproto/protodef2"
  • use go modules (introduced with go v1.11 in 2019) to ensure micro-service X gets a compatible version of protobuf Y

To point 2 - and as @PaulHankin mentioned - try not to break backward compatibility. Protobuf fields can be removed, but as long as the remaining field indices are unaltered, old client calls will still be compatible with newer proto defs.

like image 102
colm.anseo Avatar answered Sep 23 '22 21:09

colm.anseo