tRPC, Connect & Type-Safe RPC

End-to-end TypeScript RPC without codegen ceremony, Connect-RPC over HTTP/1.1 and HTTP/2, and choosing RPC stack by language boundary.

3/5Overview: 30m

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 automatically

Wins: 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

BoundaryCommon choice
Browser → backendREST, GraphQL, Connect, tRPC
Mobile → backendREST + protobuf optional, GraphQL
Service → service (polyglot)gRPC + protobuf
Service → service (TS only)tRPC or Connect
Public partner APIREST/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 boundaries

    Boundaries: (1) React SPA → Node BFF, (2) Go service → Java service, (3) public third-party integration. Pick REST, gRPC, tRPC, or Connect and justify.

    15m