Skip to content
Communication Between Services

Lesson 3 of 10 · 24 min

x
3/10

Lesson position in the course — not completion. Use Mark Complete to track finished lessons (saved in this browser).

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
1// No compile-time contract2const res = await fetch('/api/users/42');3const user = await res.json();4// user.emial is a typo — runtime bug
After
gRPC — typed contract from .proto
1// user.proto2message User {3  int32 id = 1;4  string name = 2;5  string email = 3;6}7 8service UserService {9  rpc GetUser(UserRequest) returns (User);10}11 12// Generated client — typos caught at compile time13const user = await client.getUser({ id: 42 });14console.log(user.email);

Check your understanding

  • What does a .proto file buy you?Show answer

    Answer

    A typed contract and generated clients/servers — many shape mistakes become compile-time errors.
  • Name one reason REST may still win at the edge.Show answer

    Answer

    Browser clients, human-readable JSON debugging, and no gRPC-Web/proxy requirement.
  • Name four gRPC call types.Show answer

    Answer

    Unary, server streaming, client streaming, and bidirectional streaming.
Previous

Progress is saved in this browser.

Next Lesson