gRPC and Protocol Buffers
Build fast, strongly typed service-to-service APIs with protobuf contracts and HTTP/2 streaming.
Advanced · about 6 hours · difficulty 3/5
Learn first: Resource-Oriented REST APIs
gRPC is a remote procedure call framework: you define services and messages in a .proto file with Protocol Buffers, generate client and server code for many languages, and call remote methods as if they were local functions. It runs over HTTP/2 and encodes data in a compact binary format.
Why teams use it
- Performance: binary encoding and HTTP/2 multiplexing are faster and smaller than JSON over HTTP/1.1.
- Strong contracts: the
.protofile is the source of truth, and generated code catches mismatches at compile time. - Streaming: server streaming, client streaming and bidirectional streaming are built in.
Where it fits
Mostly internal service-to-service communication in microservice systems. Browsers cannot speak native gRPC directly; you need gRPC-Web or a JSON gateway, so public APIs usually stay REST or GraphQL.
Things to learn
- Proto syntax, field numbers and why you must never reuse a removed field number.
- Deadlines (timeouts) and status codes.
- Tooling like
grpcurland Buf for linting and breaking-change detection.
You are ready to move on when you have two small services talking over gRPC with a deadline set on every call.
Key concepts
- Protocol Buffers syntax
- Code generation
- Unary and streaming RPCs
- Deadlines and status codes
- Backward-compatible proto changes
- gRPC-Web and gateways
- grpcurl and Buf
Mini project
Create an inventory service exposing a gRPC CheckStock method and call it from an order service, including a server-streaming method for stock updates.
Check yourself
Why must you never reuse the field number of a removed protobuf field?
Free resources
- gRPC documentation (gRPC)
- Protocol Buffers documentation (Google)