gRPC Communication
Protocol Buffers, HTTP/2, streaming, and when gRPC beats REST for internal service-to-service calls.
What gRPC is
gRPC is Google's high-performance RPC framework. You define services and messages in a .proto contract; the toolchain generates type-safe clients and servers in a dozen languages. Messages travel as compact Protocol Buffers binary over HTTP/2.
syntax = "proto3";
service OrderService {
rpc GetOrder (GetOrderRequest) returns (Order);
rpc WatchOrders (WatchRequest) returns (stream Order); // server streaming
}
message GetOrderRequest { string order_id = 1; }
message Order {
string id = 1;
string customer_id = 2;
int64 total_cents = 3;
OrderStatus status = 4;
}Why it's fast
Three compounding reasons: Protobuf binary payloads are 3–10× smaller than JSON and much cheaper to parse; HTTP/2 multiplexes many concurrent calls over one connection (no head-of-line blocking at the HTTP layer); and generated stubs avoid reflection-heavy serialization.
For chatty internal service-to-service traffic, the savings are significant at scale — this is why Netflix, Google, and Uber standardized on gRPC internally.
Four call styles
- Unary — classic request/response.
- Server streaming — one request, a stream of responses (live order updates).
- Client streaming — stream of requests, one response (bulk telemetry upload).
- Bidirectional streaming — both sides stream independently (chat, real-time sync).
gRPC vs REST: the honest comparison
Use gRPC for internal, high-throughput, latency-sensitive service-to-service calls where you control both ends. Use REST for public APIs, browser clients, and anywhere human readability and ubiquitous tooling matter.
The schema-first contract is also an organizational win: teams negotiate the .proto file, and compatibility rules (field numbers are forever, never reuse them) are enforced by the format itself.
Key takeaways
- gRPC = .proto contracts + generated stubs + Protobuf binary over HTTP/2.
- It excels at internal, chatty, latency-sensitive service-to-service communication.
- Four call styles: unary, server-streaming, client-streaming, bidirectional.
- Keep REST at the edge (browsers, public APIs); gRPC shines inside the mesh.
Knowledge check
Why is gRPC typically faster than REST+JSON?
A dashboard needs a live feed of order status changes. Which gRPC style fits?
In Protobuf schema evolution, what must you never do?