Skip to the page

API styles and pagination · mid

REST vs GraphQL vs tRPC vs gRPC-web, and the BFF

REST exposes resources at URLs and works naturally with HTTP caching, GraphQL lets the client ask for exactly the fields it needs from one endpoint at the cost of harder caching and server complexity, tRPC and gRPC-web are typed RPC styles, and a Backend-for-Frontend shapes APIs for one client.

The notes

What you must know

  • REST: resources + HTTP methods + status codes. Easy CDN/browser caching by URL, simple tooling. Problems: over-fetching (too many fields) and under-fetching (many round trips for one screen).
  • GraphQL: one endpoint, a typed schema, the client selects fields; good for many screens and mobile. Costs: POST requests are not HTTP-cacheable (persisted queries over GET fix this), N+1 resolver problems on the server, query cost limits, and errors often come as 200 with an errors array.
  • GraphQL clients (Apollo, Relay, urql) keep a normalised cache keyed by __typename + id, so one update refreshes every screen that shows that object.
  • tRPC: TypeScript types shared end-to-end in a monorepo, no schema file; best when the same team owns client and server in TS.
  • gRPC-web: protobuf over HTTP with generated clients; needs a proxy (Envoy) and is less human-readable; good for internal high-volume services.
  • BFF (Backend for Frontend): a thin server per client (web, app) that aggregates services, hides tokens, and returns exactly what the screen needs.

The red pen

Common traps: mistake → fix

  • Mistake: "GraphQL is always faster than REST"

    Fix: it can reduce round trips, but resolvers, no HTTP caching and big queries can make it slower.

  • Mistake: "GraphQL errors return 4xx/5xx"

    Fix: many servers return 200 with an errors array; your client must check it.

  • Mistake: "REST means one endpoint per table"

    Fix: design endpoints around client use cases; a BFF or composite endpoints solve under-fetching.

Easy to hard

Questions interviewers ask, easy to hard

  1. When would you choose GraphQL over REST for a frontend?
  2. How does caching differ between REST and GraphQL?
  3. What is a BFF and when is it worth adding?
  4. Your mobile app on 3G needs a product page that calls 6 services. How would you design the API?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview