Skip to main content
02

REST vs GraphQL vs gRPC

MediumAPI designRESTGraphQLgRPC

When would you choose REST, GraphQL or gRPC for an API?

TL;DR

REST is the default for public and general-purpose APIs: resources over HTTP, simple, and easy to cache with standard HTTP. GraphQL fits when many clients need different shapes of data from many sources: one endpoint, the client asks for exactly the fields it needs, no over- or under-fetching. gRPC fits internal service-to-service calls: binary Protobuf over HTTP/2, strongly typed contracts, streaming, and low latency, but it's awkward in browsers.

Key points

RESTGraphQLgRPC
ContractOpenAPI (optional)Schema (required).proto (required)
PayloadJSONJSONBinary Protobuf
HTTP cachingBuilt inHard (mostly POST to one URL)None
Browser supportNativeNativeNeeds gRPC-Web or a proxy
Best forPublic APIs, CRUDRich UIs, aggregating backendsInternal microservices, streaming
  • GraphQL risks: N+1 resolvers (fix with DataLoader batching), expensive nested queries (limit depth and cost), and field-level authorization.
  • gRPC gives generated clients in many languages and built-in deadlines.
  • Many companies combine them: gRPC inside, REST or GraphQL at the edge.

Example

graphql
query {
  user(id: "42") {
    name
    orders(last: 3) {
      id
      total
    }
  }
}

One request replaces GET /users/42 plus GET /users/42/orders?limit=3.

Common follow-ups

  • How do you version each? REST: URL or header versioning (/v2). GraphQL: evolve the schema and deprecate fields instead of versioning. gRPC: add fields with new numbers and never reuse old ones.
  • What's a BFF? A backend-for-frontend: a thin API per client (web, mobile) that aggregates internal services. GraphQL often plays this role.

What interviewers look for

Tip

Choose by consumer and constraints (public vs internal, caching, payload shape, latency), not by hype.

  • Red flag: "GraphQL is the newer REST, so always use it."

Was this helpful?

Related questions