tRPC — TypeScript end-to-end
Monorepo pattern: define router with Zod-validated inputs; client imports type of router — full inference without OpenAPI codegen.
// server
export const appRouter = router({
getUser: publicProcedure.input(z.object({ id: z.string() })).query(({ input }) => ...),
})
// client — input/output types flow automaticallyWins: DX for full-stack TS teams, fast iteration, built-in validation.
Limits: TypeScript-only boundary; not for polyglot microservices. Transport is HTTP/JSON (or experimental links) — not protobuf performance.
Best for: Next.js app ↔ API routes, internal admin tools, startups with one language.
Connect-RPC
Modern alternative from Buf: protobuf services over standard HTTP. Single server speaks:
- Connect protocol (simple HTTP, works with curl)
- gRPC (HTTP/2)
- gRPC-Web (browsers)
Interoperates with existing gRPC backends; easier debugging than raw gRPC.
gRPC-Web
Browsers cannot do raw HTTP/2 gRPC. grpc-web JS client → Envoy/Istio proxy → gRPC backend. Adds latency and config complexity — why many teams use REST/GraphQL north-south and gRPC east-west.
Choosing RPC by boundary
| Boundary | Common choice |
|---|---|
| Browser → backend | REST, GraphQL, Connect, tRPC |
| Mobile → backend | REST + protobuf optional, GraphQL |
| Service → service (polyglot) | gRPC + protobuf |
| Service → service (TS only) | tRPC or Connect |
| Public partner API | REST/OpenAPI, webhooks |
Reflection and tooling
gRPC server reflection enables grpcurl without proto files. Essential for debugging in staging.
Buf — lint, breaking change detection, codegen pipeline for protos at scale.
Interview depth
Explain why Netflix/Uber moved internal traffic to gRPC: typed contracts, perf, streaming, uniform interceptors (auth, metrics, retries). Acknowledge operational cost: proto governance, LB config, browser gap.
Cross-reference: Service mesh mTLS and retries in Deep Cuts; Networking for HTTP/2 under gRPC.
Further Reading
Hands-On Tasks (Optional)
API design drills and whiteboard exercises — protocol selection, contract design, and bulk-transfer architecture. Assumes Networking and sibling tracks on the hub page (Distributed Systems, Databases, Concurrency, LLD).
- Choose RPC stack for three boundaries15m
Boundaries: (1) React SPA → Node BFF, (2) Go service → Java service, (3) public third-party integration. Pick REST, gRPC, tRPC, or Connect and justify.