Card 06/ 09

ComparisonDifficulty: Intermediate1 min

REST vs GraphQL vs gRPC

Choose by who the clients are, how varied their needs are, and whether browsers and caches must understand the traffic.

Choosing an API style means matching its trade-offs to the integration's clients. REST reaches every client and works with HTTP caches; GraphQL lets varied clients take exactly the data they need; gRPC gives fast, strongly typed calls between services. Many systems use more than one: gRPC between internal services, with REST or GraphQL at the edge.

Each property across the three styles
PropertyRESTGraphQLgRPC
Who shapes the responseThe server, per resourceThe client, per queryThe server, per procedure
HTTP cachingBuilt in, per URLNeeds extra workNot by HTTP caches
Contract and typingOptional, such as OpenAPIA required, typed schemaA required .proto, with generated code
Browser clientsNativeNativeNeeds gRPC-Web and a proxy
Payload size and speedLarger, textFits the query, textSmall, binary, over HTTP/2
StreamingServer-sent events or WebSockets alongsideSubscriptions, usually over WebSocketsBuilt in, four shapes
EvolutionVersions or additive changesAdd fields, deprecate old onesNew field numbers, reserved old ones
Ease of trying by handcurl and a browserAn explorer such as GraphiQLNeeds a gRPC tool
Typical fitPublic and partner APIsFront ends with many varied screensInternal service-to-service calls

Choose REST when the clients are many and unknown, such as partners and the public, when caching matters, and when anyone should be able to try the API with curl.

Choose GraphQL when one team builds front ends with many screens over the same data, and the cost of a request per resource, or of a custom endpoint per screen, has become the bottleneck.

Choose gRPC when both ends are services the team owns, calls are frequent, payloads and latency matter, and streaming is needed.

So decide by the clients first; the style that suits them decides most of the rest.