1

When writing a .proto file for gRPC I have noticed that I can either.

1) Include all my messages (requests and responses) inside one .proto file along with all the rpcs.

2) Write each rpc in its own .proto file.

I can see that when I have two rpcs that access the same messages it is more convenient to write the protocol buffers in the same file. However I would prefer to split them up when possible to take the more modular approach.

My question is, ignoring preference is there any efficiency difference between these two approaches? Also any info on convention here would be appreciated.

NOTE: I am using gRPC (C++ and Java) I don't know if the language implementation has something to do with the answer.

1
  • No. But have you heard of FlatBuffers? Of course, we can't even begin to talk about efficiency without some benchmarks. Commented Apr 15, 2020 at 23:44

1 Answer 1

1

There is no difference in efficiency. Some languages import generated code based on the proto file name, e.g., C++ and Java if not setting option java_multiple_files = true, so the difference is visible outside of the .proto files themselves. But nothing impacting performance.

The only limitation is that all methods of a service have to be in one file. But the messages for those methods can still be in separate files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.