- Go 100%
| cmd | ||
| gen/greet/v1 | ||
| proto/greet/v1 | ||
| .gitignore | ||
| buf.gen.yaml | ||
| buf.yaml | ||
| go.mod | ||
| go.sum | ||
| README.md | ||
golang-grpc-demo
A minimal demo of a Go server and client communicating over
protobuf using gRPC (grpc-go) and
protobuf-go. Everything is managed with the Go module system
(go.mod / go.sum) — no global installs required.
This is the Go counterpart of the sibling repos, all sharing the same schema, all four RPC modes, and the same benchmark methodology:
pyrpc-demo— Connect RPC + protobuf-py (Python)pygrpc-demo— gRPC + classic protobuf (Python)rust-grpc-demo— gRPC + tonic/prost (Rust)- this repo — gRPC + protobuf-go (Go)
Project layout
proto/greet/v1/greet.proto # the schema: greet.v1.GreetService (4 RPC modes)
buf.yaml / buf.gen.yaml # codegen via Buf remote plugins (Go plugins)
gen/greet/v1/greet.pb.go # generated messages (checked in, idiomatic Go)
gen/greet/v1/greet_grpc.pb.go# generated gRPC stubs (checked in)
cmd/server/main.go # gRPC server
cmd/client/main.go # gRPC client
cmd/benchmark/main.go # performance benchmark (codec + RPC throughput)
Dependencies (go.mod)
| Dependency | Why it's here |
|---|---|
google.golang.org/grpc |
gRPC runtime (server + client, HTTP/2 via net/http2). |
google.golang.org/protobuf |
protobuf-go runtime for the generated message types. |
Codegen uses Buf remote plugins (buf.build/protocolbuffers/go and
buf.build/grpc/go), which run on Buf's servers — so neither protoc nor
protoc-gen-go needs to be installed locally. The generated files are
checked in (idiomatic Go); regenerate with any buf binary, e.g. from a
sibling pyrpc-demo venv:
/path/to/pyrpc-demo/.venv/bin/buf generate
Run
go run ./cmd/server # terminal 1
go run ./cmd/client # terminal 2
Expected client output (all four RPC kinds):
--- unary: Greet ---
[client] Hello, world!
--- server streaming: GreetStream ---
[client] Hello #1, streamer!
[client] Hello #2, streamer!
[client] Hello #3, streamer!
--- client streaming: GreetCount ---
[client] server counted 3 requests
--- bidirectional streaming: GreetChat ---
[client] Hi, alice!
[client] Hi, bob!
[client] Hi, carol!
Benchmark
Same methodology as the sibling repos:
- Codec — in-process serialize/deserialize of
GreetRequestat 64 / 128 / 256 / 512 / 1024 / 2048 KiB payloads, each timed ≥0.5 s per direction. - Unary throughput vs concurrency — 2,000
Greetround-trips at each concurrency level (1, 4, 16, 64), with live TCP connection counts (vialsofon macOS,sson Linux). - Unary throughput, large payloads — 200 round-trips, 2 MiB payloads.
- Bidi streaming throughput — 5,000 messages over one
GreetChatstream.
go run ./cmd/server # terminal 1
go run ./cmd/benchmark # terminal 2
See the cross-language results table in
pyrpc-demo's README.