Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

gRPC
HLD

gRPC

Contract-first binary RPC — protobuf schemas, HTTP/2 streams, and where gRPC earns its complexity.

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

StrengthsFrictions
Typed contracts via codegenBrowser support requires gRPC-Web + proxy
Small fast wire formatHuman-unreadable payloads (need tooling)
Streaming primitivesHTTP caching forfeited
Deadlines/cancellation propagatedError model ≠ HTTP status semantics
Polyglot by defaultProto 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.

My Private Notes

Notes are auto-saved locally to this device.