37

Since you have to share .proto files to define data and services for gRPC, service provider and clients need to access the same .proto files. Is there any common strategy to distribute these files? I want to avoid that every project has its own .proto file in its Git repository and our team members need to manual edit these files or share them via email.

Is there any common best practice?

Milgo
  • 2,617
  • 4
  • 22
  • 37
  • Not sure about the common best practices, how my company has done this in the past is, have a central repository host all (most) proto files as well as the generated code. Usually projects in `GoLang` or `Node.JS` simply pull the latest version on build or people try to pull the latest release of the proto definitions for their projects. Whenever a new proto change is made to master, the CI generates a release with generated code. – ishaan May 01 '19 at 16:49
  • 4
    You might also consider sharing your `.proto` files using [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules). – Richard Belleville May 01 '19 at 17:19

2 Answers2

18

Unfortunately, there is no common practice, although the main goal that you should achieve is to store proto files in one version control repository.

During my investigation, I've found some interesting blog posts about that subject:

They covers much of gRPC workflow considerations. Hope that helps!

kkochanski
  • 2,178
  • 23
  • 28
  • 1
    While I think I understand the reasoning for grouping proto files into a singular repo for what appears to the outside world as an singular application (meaning I don't need to know how many services/components are underneath your API to use it), for inside of a service network where services evolve independently, would it make sense to allow the running services to publish their own .proto files similar to a swagger endpoint? Then I'd always know what the contract is at a specific service instance, and need not couple 100% of my ecosystem's service interfaces. – Scott Sep 28 '22 at 22:37
  • 1
    There's already built-in mechanism for publishing the contract of the service. Take a look at Server Reflection - https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md. Got it at my Java services as well. – kkochanski Sep 29 '22 at 10:18
  • 1
    Thanks @kkochanski, blogs were very helpful – Himanshu Sep 01 '23 at 16:49
3

In terms of best practices in sharing gRPC definitions, I would suggest instead of sharing those files, to use GRPC Server Reflection Protocol (https://github.com/grpc/grpc/blob/master/doc/server-reflection.md)

Luan Kevin Ferreira
  • 1,184
  • 2
  • 16
  • 40