GraphQL vs REST
Both are transport-layer API styles. Different shapes of the same problem: moving structured data between client and server.
1 credit
The one-line diff
- **REST**: server defines resources (URLs) and their shapes; client takes what it's given.
- **GraphQL**: client sends a query describing exactly which fields it wants from a typed schema; server returns exactly that.
When GraphQL shines
- Many clients (web, iOS, Android) need different slices of the same data.
- Avoiding N+1 round-trips — single query can fetch a user + their posts + comments.
- Schema is first-class — auto-generated types/docs/playground.
- Evolving APIs without versioning (deprecate fields gradually).
When REST shines
- Caching — HTTP cache-friendly out of the box (GraphQL POSTs aren't).
- Public APIs — URLs are discoverable, status codes are obvious.
- Simple CRUD — mental overhead of GraphQL is wasted.
- You don't control the consumer (3rd-party integrations prefer REST).
GraphQL gotchas
- N+1 resolvers — flat-looking queries can fan out into dozens of DB reads. Use DataLoader.
- Complex queries can DoS your backend — add query depth/complexity limits.
- Uploads, binary data, streaming — all easier in REST.
- Error handling is bespoke (HTTP 200 + `errors` array).