Welcome to Go Protobuf & gRPC
You know how to build HTTP services in Go. JSON in, JSON out, net/http, done. That works for most things. But when your services need to talk to each other at scale, JSON starts showing its limits. It's slow to parse, there's no schema enforcement, and every team ends up writing their own request/response structs that drift apart over time.
Protocol Buffers fix this. You define your data once in a .proto file, generate Go code from it, and get a binary format that's smaller, faster, and version-safe. gRPC builds on top of that and gives you a real RPC framework with streaming, deadlines, and interceptors built in.
Google created Protobuf internally around 2001 and open-sourced it in 2008. Every Google service uses it. It's not a toy, it's not a trend. It's battle-tested infrastructure.
What We're Building
A link shortener service that communicates over gRPC. We'll define the API in .proto files, generate Go code, build the server and client, add streaming, interceptors, error handling, and tests. By the end, we'll expose the same service as a REST API using gRPC-Gateway.
Why a link shortener? The domain is dead simple โ store a URL, return a short code, resolve it later. That simplicity is the point. You won't get lost in business logic. Instead, all your attention goes to Protobuf and gRPC mechanics. And despite the simple domain, it naturally exercises every gRPC pattern: unary calls for creating and resolving links, server streaming for real-time click analytics, client streaming for batch imports, and bidirectional streaming for live dashboards. It's also a service everyone already knows as a REST API, so when we add gRPC-Gateway at the end, the comparison is immediate.
What You'll Learn
- Protobuf basics: what it is, why it exists, when to use it over JSON
- Proto3 syntax: messages, enums, nested types, maps, oneof
- Code generation:
protocwith Go plugins, Makefile automation - Serialization: marshal/unmarshal, binary format, size comparison
- Schema evolution: adding fields without breaking clients
- gRPC fundamentals: HTTP/2, unary RPC, service definitions
- Server & client: implement, register, dial, call
- Streaming: server streaming, client streaming, bidirectional
- Interceptors: logging, auth, the gRPC equivalent of middleware
- Error handling: status codes, rich error details
- Metadata & deadlines: context propagation, timeouts
- Testing: in-memory testing with
bufconn, no network needed - gRPC-Gateway: expose gRPC as REST for when you need both
Prerequisites
Complete Go in Practice or have equivalent experience building Go services. You should be comfortable with net/http, structs, interfaces, and error handling. Familiarity with Go Essentials and Go Concurrency Patterns helps but isn't required.
When to Use Protobuf & gRPC
Use it when services talk to services. Microservices, internal APIs, high-throughput systems where JSON parsing is a bottleneck, mobile clients that care about payload size, anything that needs strict contracts between teams.
Don't use it for public REST APIs that humans debug with curl. Don't use it for simple CRUD apps where JSON is fine. Don't use it because it sounds cool. Use it when you actually need schema enforcement, binary efficiency, or streaming.
Let's build something.