When would you choose REST, GraphQL or gRPC?
MediumConceptAPIs & Communication
Answer
Choose REST for public, resource-oriented APIs where simplicity, HTTP caching and broad tooling matter. Choose GraphQL when varied clients need exactly the fields they want from several related resources in one request. Choose gRPC for low-latency communication between internal services.
- REST: easy to cache and debug, but it can over-fetch or need several round trips for nested data.
- GraphQL: a single endpoint with a typed schema avoids over- and under-fetching; HTTP caching is harder, and expensive queries need depth or cost limits.
- gRPC: Protocol Buffers over HTTP/2 give compact binary messages, generated clients and streaming; browsers need a proxy such as gRPC-Web.
- Many systems combine them: REST or GraphQL at the edge, gRPC between internal services.
More in APIs & Communication
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | What is a REST API, and what makes an API RESTful? | Concept | Easy | Read the answer to What is a REST API, and what makes an API RESTful? | |||
| 2 | When would you choose REST, GraphQL or gRPC? | Concept | Medium | Read the answer to When would you choose REST, GraphQL or gRPC? | |||
| 3 | What is idempotency, and how do you make a POST request safe to retry? | Concept | Medium | Read the answer to What is idempotency, and how do you make a POST request safe to retry? | |||
| 4 | How do short polling, long polling, WebSockets and Server-Sent Events differ? | Concept | Medium | Read the answer to How do short polling, long polling, WebSockets and Server-Sent Events differ? |