gRPC & schema-first APIs

Protobuf, streaming RPCs, deadlines, backward-compatible field evolution. Know when gRPC beats REST (internal service mesh) and when it hurts (browser clients).

About 27 min read3-question knowledge check

The mental model

gRPC is a **typed phone line between two programs that agreed on the script in advance**. Before either side writes a line of code, they share one file — the .proto — that lists exactly which calls exist, what arguments each takes, and what it returns. A compiler turns that file into client and server stubs in whatever languages each side uses. Calling a remote method then feels like calling a local function: client.GetOrder(req), strongly typed, autocompleted, no URL to remember and no JSON to hand-parse.

The two ideas that make gRPC what it is: schema-first (the contract is a real artifact you compile against, not prose in a wiki) and binary framing over HTTP/2 (messages are Protobuf-encoded and streams are multiplexed, so it is compact and fast).

**Why this exists — what breaks without it.** In a REST-between-services world, the contract lives in documentation that drifts, and every service re-implements request parsing, validation, and error mapping by hand. A field renamed on the server silently becomes null on the client with no compiler complaint — you find out in production. Payloads are verbose JSON parsed with reflection, which becomes a measurable CPU cost at high internal fan-out. There is no first-class streaming, so a server that wants to push updates is stuck polling. gRPC answers all four: the .proto is compiled so a breaking change fails the build, Protobuf is compact and fast to parse, HTTP/2 gives real bidirectional streaming, and deadlines are part of the call rather than an afterthought.

The catch that defines *when* to use it: browsers cannot speak gRPC directly (no raw access to HTTP/2 framing), so gRPC shines between your own services and hurts at the public browser edge.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision