Communication Between Services

Lesson 3 of 10 · 24 min

x
30%

gRPC & Protocol Buffers

gRPC is a high-performance RPC framework built on HTTP/2. Instead of JSON over REST, you define your API in a .proto file and generate strongly typed client and server code. Protocol Buffers serialize data in a compact binary format — smaller payloads and faster parsing than JSON. gRPC supports four call types: unary (one request, one response), server streaming, client streaming, and bidirectional streaming. For internal microservice meshes where both ends run gRPC, it routinely outperforms REST. The downside: browsers need a gRPC-Web proxy, and debugging binary payloads is harder than reading JSON in DevTools.

Before
REST — untyped JSON
// No compile-time contract
const res = await fetch('/api/users/42');
const user = await res.json();
// user.emial is a typo — runtime bug
After
gRPC — typed contract from .proto
// user.proto
message User {
  int32 id = 1;
  string name = 2;
  string email = 3;
}

service UserService {
  rpc GetUser(UserRequest) returns (User);
}

// Generated client — typos caught at compile time
const user = await client.getUser({ id: 42 });
console.log(user.email);

Key Takeaway

Use gRPC for high-throughput internal APIs where type safety and binary efficiency matter more than browser compatibility.

PreviousNext Lesson