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
| REST | GraphQL | gRPC | |
|---|---|---|---|
| Contract | OpenAPI (optional) | Schema (required) | .proto (required) |
| Payload | JSON | JSON | Binary Protobuf |
| HTTP caching | Built in | Hard (mostly POST to one URL) | None |
| Browser support | Native | Native | Needs gRPC-Web or a proxy |
| Best for | Public APIs, CRUD | Rich UIs, aggregating backends | Internal 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."