What Is tRPC? tRPC vs REST, GraphQL and gRPC
On this page
The problem tRPC solves
Picture a typical React app talking to a Node API. The server returns a task like { id, title, done }. On the client, someone writes a Task type by hand, a fetch call, and a bit of parsing. It works until a backend developer renames done to completed. The server compiles, the client compiles, and the bug shows up in production as tasks that are never ticked.
The two sides disagree because nothing connects them. The client's Task type is a copy, and copies drift.
The usual fixes add a contract in the middle. You write an OpenAPI spec or a GraphQL schema, then generate client types from it. That works well, and for public APIs it's the right call. But for a team that owns both the frontend and the backend in TypeScript, it adds a build step, a file to keep in sync, and a lot of ceremony for an API only your own app calls.
How tRPC works
tRPC takes a different route. You write server functions, called procedures, and group them in a router. The client imports the router's *type*, not its code, and TypeScript infers every procedure's input and output from it.
// server: a procedure is a function with a validated input
export const appRouter = router({
greet: publicProcedure
.input(z.object({ name: z.string() }))
.query(({ input }) => `Hello, ${input.name}`),
});
export type AppRouter = typeof appRouter;// client: only the type crosses over, so no server code ends up in the bundle
import type { AppRouter } from '../server/router';
const msg = await trpc.greet.query({ name: 'Ada' }); // msg: string
await trpc.greet.query({ nam: 'Ada' }); // compile error: 'nam' does not existRename a field on the server and every client call that uses it turns red in your editor before you save. That's the whole pitch: the server code is the contract.
Under the hood it's ordinary HTTP. A query becomes a GET with the input in the URL, a mutation becomes a POST with a JSON body, and several calls made at the same moment can be batched into one request. You'll look at the exact wire format on Day 2.
The name means "TypeScript Remote Procedure Call". Alex Johansson started the project in 2020, and the current major version is v11 (11.23 as of November 2026), which this course uses together with Zod 4 and TanStack Query 5.
tRPC compared with REST, GraphQL and gRPC
tRPC is not a replacement for every API style. It's a sharp tool for one situation.
- REST with OpenAPI is the default for public APIs. Any language can call it, HTTP caching works naturally, and the spec doubles as documentation. The cost is keeping the spec and the code in sync, usually through code generation.
- GraphQL shines when many different clients need different slices of a large graph of data. It brings its own schema language, a query language for clients, and server complexity around resolvers and query cost.
- gRPC uses Protocol Buffers and HTTP/2 for fast, strongly typed calls between services in many languages. Browsers can't speak it directly without a proxy.
- tRPC has no schema language at all. It's TypeScript-only and works best when the client and server live in the same repository.
When tRPC is a good fit
Reach for tRPC when most of these are true:
- Both the client and the server are TypeScript.
- One team, or a few close teams, own both sides.
- The code lives in a monorepo, or the server's types can be shared as a package.
- The API exists to serve your own app, not outside developers.
- The client and server ship together, or close together.
A full-stack Next.js app, a React app with a Fastify backend in the same repo, or a backend-for-frontend layer (the BFF course covers that pattern) are all classic fits.
When tRPC is the wrong choice
Be honest about the limits:
- Public or partner APIs. Outside developers want documentation, stable versions and clients in their own language. tRPC gives them none of that by default.
- Non-TypeScript clients. A Swift or Kotlin mobile app gets no type benefit. It can call tRPC endpoints over HTTP, but it's an awkward, undocumented format to hand-code against.
- Independent release cycles. If a mobile app version stays installed for months, the server can't freely change procedure shapes. tRPC has no built-in versioning, so you have to manage compatibility by hand (Day 12).
- Heavy HTTP caching needs. Queries use
GET, so caching is possible, but REST resources with clean URLs are much easier to cache at a CDN.
A common pattern is to use tRPC for your own web app and expose a small REST API next to it for outside callers. Both can share the same service code underneath.
What you'll build in this course
You'll build the API for TaskBoard, a small task tracker, step by step: a router with validated input, authentication middleware, typed errors, Fastify and Express servers, a React client with TanStack Query, optimistic updates, infinite scrolling and live updates over Server-Sent Events. Every code sample was run against tRPC 11.23 while writing the course, and the outputs shown are real.
You'll need Node 20 or newer and TypeScript 5.7 or newer, which is the minimum tRPC 11 supports, with strict mode turned on. Without strict, much of the type inference you're here for quietly stops working.
Check yourself
Only the router's type, with import type. That gives the client full inference of inputs and outputs while no server code ends up in the browser bundle.
No. Partners get no TypeScript types and no standard documentation. A REST API with an OpenAPI spec suits them better, and you can still use tRPC for your own TypeScript frontend.
tRPC's whole value comes from type inference. Without strict, TypeScript treats values that might be null or undefined loosely and lets implicit any slip through, so a renamed field or a missing input can compile without an error. Turn strict on in every package that touches the router, client included.
Both use plain HTTP, but REST is designed around resources and URLs that any client can call, usually described by an OpenAPI spec. tRPC is designed around procedures, and the contract is the server's TypeScript type rather than a separate spec. That removes code generation and drift for TypeScript clients, at the cost of being much less useful to anyone outside your codebase.
It can, because tRPC endpoints are ordinary HTTP, but it gets none of the type safety and must hand-code an undocumented wire format. Worse, old app versions stay installed for months, so every procedure change risks breaking them. A small versioned REST API for the mobile app, sharing service code with the tRPC procedures, is usually the safer design.