API Design interview question · Most asked
When would you choose GraphQL over REST, or gRPC over both?
Summary
GraphQL suits client-driven data needs (many screens/clients needing different shapes, avoiding over/under-fetching) with a typed schema; REST suits resource-oriented public APIs with HTTP caching and simplicity; gRPC suits low-latency internal service-to-service calls with strict contracts and streaming.
Longer Answer
GraphQL trade-offs: caching complexity, N+1 resolvers, query cost control. gRPC trade-offs: browser support needs gRPC-Web/Connect, binary payloads are harder to debug. Many architectures use REST/GraphQL externally and gRPC internally.
Key Points
- GraphQL: flexible client queries
- REST: simple, cacheable, public
- gRPC: fast internal contracts
- Mix by audience
Comparison / Tradeoffs
| REST | GraphQL | gRPC | |
|---|---|---|---|
| Contract | OpenAPI | Schema (SDL) | Protobuf |
| Caching | HTTP-native | Harder | Custom |
| Best for | Public APIs | Diverse clients | Internal RPC |
More most-asked API Design questions
- What makes an API RESTful, and what are good REST design practices?
- Which HTTP methods are safe and idempotent, and why does it matter?
- Which HTTP status codes should an API use, and when?
- Compare offset pagination and cursor (keyset) pagination.
- How should you version an API?
- How do idempotency keys work for POST requests?