Demo code grpc and golang.
Find a file
2026-09-08 17:49:08 +02:00
cmd gRPC demo in Go: grpc-go + protobuf-go, all 4 RPC modes, benchmark 2026-09-08 17:33:36 +02:00
gen/greet/v1 gRPC demo in Go: grpc-go + protobuf-go, all 4 RPC modes, benchmark 2026-09-08 17:33:36 +02:00
proto/greet/v1 gRPC demo in Go: grpc-go + protobuf-go, all 4 RPC modes, benchmark 2026-09-08 17:33:36 +02:00
.gitignore gRPC demo in Go: grpc-go + protobuf-go, all 4 RPC modes, benchmark 2026-09-08 17:33:36 +02:00
buf.gen.yaml gRPC demo in Go: grpc-go + protobuf-go, all 4 RPC modes, benchmark 2026-09-08 17:33:36 +02:00
buf.yaml gRPC demo in Go: grpc-go + protobuf-go, all 4 RPC modes, benchmark 2026-09-08 17:33:36 +02:00
go.mod gRPC demo in Go: grpc-go + protobuf-go, all 4 RPC modes, benchmark 2026-09-08 17:33:36 +02:00
go.sum gRPC demo in Go: grpc-go + protobuf-go, all 4 RPC modes, benchmark 2026-09-08 17:33:36 +02:00
README.md README: link sibling repos via git.burakemir.ch URLs 2026-09-08 17:49:08 +02:00

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:

  1. Codec — in-process serialize/deserialize of GreetRequest at 64 / 128 / 256 / 512 / 1024 / 2048 KiB payloads, each timed ≥0.5 s per direction.
  2. Unary throughput vs concurrency — 2,000 Greet round-trips at each concurrency level (1, 4, 16, 64), with live TCP connection counts (via lsof on macOS, ss on Linux).
  3. Unary throughput, large payloads — 200 round-trips, 2 MiB payloads.
  4. Bidi streaming throughput — 5,000 messages over one GreetChat stream.
go run ./cmd/server     # terminal 1
go run ./cmd/benchmark  # terminal 2

See the cross-language results table in pyrpc-demo's README.