Search code examples
grpc

Best way to have proto folder for multiple platform


What is the best practice to hold proto folder for multiple platform, such as backend, iOS, Android, and Web? I came up with 3 ideas. Which one would be the best? Do you know better ideas than them?

1st: Should I have all in 1 repository including proto folder?

2nd: Should I split all like proto repo, iOS repo, backend repo etc, and share proto folder as a git submodule?

3rd: Should I make independent proto folder for all repos?


Solution

  • My recommendation is that you use one repository for your proto files and use something like git submodules to include it in other repositories. The reasons are the following:

    • Proto files generally change way less often than your code, so low overhead when using git submodules (no need to git pull all the time).

    • It prevents having different versions of your proto files which can lead to unexpected behaviours when field tags are mismatching.

    • Modularity. If later you decided to do another project (eg: Desktop app) with the same proto files, you would just add a submodule, not copy everything and make specific changes to your project.

    Furthermore, proto files are design to be shared across different language by being able to add options for specific languages. If you use this submodule in a iOS project and generate code for Swift only the options for Swift will be taken into account, same for Kotlin/Java and same for JS.

    Even though I believe this is the safest way to manage your proto files, that's only my recommendation. Different use cases might need different architecture.