Card 09/ 09

RecapDifficulty: Advanced1 min

Recap: REST, GraphQL and gRPC

Resources for broad reach, queries for varied screens, procedures for fast typed calls between services.

Each style answers a different question about who shapes the data and who the clients are.

  • REST exposes resources at URLs; every client can call it and every HTTP cache understands it.
  • GraphQL exposes one endpoint and a schema; the client names the fields and gets exactly those.
  • gRPC exposes procedures from a .proto file, called with generated code over HTTP/2.
  • Over-fetching and under-fetching are REST's cost for varied screens, and GraphQL's reason to exist.
  • Protobuf field numbers are the contract: add new ones, reserve removed ones, never reuse one.
  • GraphQL needs cost limits: depth, list sizes and query cost, or one request can ask for everything.
The decisions that pick each style
DecisionRESTGraphQLgRPC
The clients areMany and unknownYour own varied front endsYour own services
The priority isReach and cachingFitting each screenSpeed and typing
Browsers call itYesYesOnly through gRPC-Web