The Machinery
.proto file (the contract):
service TripService {
rpc GetTrip(GetTripRequest) returns (Trip);
rpc TripUpdates(TripId) returns (stream TripUpdate); // server stream
}
message Trip {
string trip_id = 1;
TripStatus status = 2;
}
codegen → typed client + server stubs in every supported language.
the schema IS the API; drift between teams becomes impossible to hide
Protobuf: Binary and Versioned
wire format: field NUMBER + type, not field names
{"trip_id": "x"} JSON ~20 bytes → tag+varint ~6 bytes
evolution rules built into the encoding:
NEVER reuse/renumber a field tag; reserve removed ones
new fields = new numbers → old readers skip unknown tags
that's backward+forward compat BY CONSTRUCTION,
which JSON conventions only get through discipline
HTTP/2 Underneath
HTTP/1.1: one in-flight request per connection (or many conns)
HTTP/2: MULTIPLEXED streams on one connection
gRPC rides this:
- concurrent calls without head-of-line blocking at HTTP layer
- bidirectional streaming as a first-class primitive
- header compression cuts per-call overhead for chatty meshes
types of streaming available:
unary req → res classic call
server stream req → stream of res live trip locations
client stream stream of req → res batch uploads
bidi stream ↔ stream chat, telemetry
Where gRPC Shines vs Hurts
| Strengths | Frictions |
|---|---|
| Typed contracts via codegen | Browser support requires gRPC-Web + proxy |
| Small fast wire format | Human-unreadable payloads (need tooling) |
| Streaming primitives | HTTP caching forfeited |
| Deadlines/cancellation propagated | Error model ≠ HTTP status semantics |
| Polyglot by default | Proto discipline required (tag rules) |
The deadline propagation row is underrated: gRPC threads a deadline through every hop automatically, so the whole chain gives up together instead of orphaning work.
The Ecosystem Slot
gRPC grew up with microservices/meshes:
- sidecar proxies speak it natively (mTLS, LB, retries)
- health-check protocols standardized
- per-request auth metadata defined
typical production shape:
browsers ──REST──► gateway ──gRPC──► services ──gRPC──► services
Interview Framing
Mention gRPC when the design has internal service-to-service traffic, streaming needs, or polyglot teams — with reasons (“binary contracts prevent cross-team drift; deadlines propagate”). Expect the follow-up “why not everywhere?” — answer browser/cacheability frictions. Knowing both sides reads as experience; evangelizing it universally reads as résumé-driven design.
Premium Content
Unlock gRPC and all premium lessons with a subscription.
All premium lessons
Ad-free experience
Priority support
From ₹199.99/year — See plans