# README
grpc-proto
GRPC Proto playground
Scope
A few things that I'd like to achieve:
- Compile protobuf services with RPC & HTTP supports
- Setup client/server for GRPC communication via Go & JavaScript
- Play around with Bazel a bit
Setup Requirements
# Setup prerequisite
$ brew install buildifier bazelisk
For Editor Setup, please checkout this document
Command lines
# To list out all existing rules (including auto-generated rules)
# Rules like `//:.aspect_rules_js/node_modules/@[email protected]` is auto-generated
$ bazelisk query "//..."
# Start the Go server. Fixed ports: 9090 for gRPC, 9000 for HTTP
$ bazelisk run "//cmd/server"
# Start the JavaScript server
$ bazelisk run "//src:js_server"
# Send the HTTP payload to port 9000
$ bazelisk run "//cmd/client/http:client
# Send the gRPC payload to port 9090
$ bazelisk run "//cmd/client/rpc:client
# Send the gRPC payload to port 9090
$ bazelisk run "//src:js_client"
# Sync Go package dependencies with go.mod
$ gazelle update-repo
# Sync Go package dependencies in BUILD
$ gazelle update
Learning
There are several components inside of this POC:
- Build system (Bazel)
- Type definition (Protobuf)
- Implementation (gRPC related packages)
Bazel
Bazel is the open source version of Google's Blaze. It's a pain killer for managing projects in monorepo (after experiencing diffferent gotchas of npm workspaces
). Via deps
options, you cherry pick the packages you need to build the corresponding binaries. Being explicit for package imports helps me to trim unused dependencies, reducing the binary size. However, it has its own caveats:
- The learning curve is steep
- The community is still growing, and many things are still under development
rules_go
has an official support via Protobuf already. Butrules_ts
's support is still WIP.
Protobuf
Protobuf defines data schema that can be shared across different languages. But also, the protobuf can be sent as binary data and it's more packed than JSON. Other program languages can't interperate Protobuf files directly, and it needs a compiler to compile the proto definition into their languages. The common one is protoc
.
gRPC related packages
Protobuf has services, but they are RPC services. Thus, the default HTTP modules may struggle to inteperate them directly. Additional gRPC packages need to be installed/setup to make sure both client and server understand the protocol.