Skip to content

Instantly share code, notes, and snippets.

@lreverchuk
Last active June 13, 2026 10:58
Show Gist options
  • Select an option

  • Save lreverchuk/e143383466ad15f8694a01920d42655f to your computer and use it in GitHub Desktop.

Select an option

Save lreverchuk/e143383466ad15f8694a01920d42655f to your computer and use it in GitHub Desktop.
GraphQL vs REST: Differences, Trade-offs & When to Use Each

GraphQL vs REST: Differences, Trade-offs & When to Use Each

A practical comparison of GraphQL and REST: how they differ, where each shines, and how to choose. Includes concrete request examples and a decision guide.

The one-sentence difference

REST exposes many endpoints, each returning a fixed shape. GraphQL exposes one endpoint where the client specifies exactly the shape it wants.

Side-by-side

Aspect REST GraphQL
Endpoints Many (/users, /users/1/posts) One (/graphql)
Data shape Fixed by the server Chosen by the client
Over/under-fetching Common Avoided by design
Fetching related data Multiple round trips One query
Versioning /v1, /v2 URLs Evolve the schema (deprecate fields)
Caching Easy (HTTP/URL caching) Harder (needs client/normalized cache)
Learning curve Low Higher
File uploads / binary Native Needs extra spec
Error handling HTTP status codes 200 + errors array
Tooling/introspection OpenAPI/Swagger Built-in schema introspection

The problems GraphQL solves

Over-fetching: A REST /users/1 returns the whole object even if you need only the name. GraphQL returns just what you ask for.

Under-fetching (N+1 round trips): To show a user with their posts and each post's comments, REST often needs several calls. GraphQL fetches it in one query.

query {
  user(id: "1") {
    name
    posts {
      title
      comments { body }
    }
  }
}

The equivalent in REST:

GET /users/1
GET /users/1/posts
GET /posts/{id}/comments   (repeated per post)

Where REST still wins

  • Caching, HTTP caching, CDNs, and ETag/Cache-Control work out of the box on URL-based resources. GraphQL's single POST endpoint bypasses that.
  • Simplicity, fewer moving parts; any HTTP client works.
  • File downloads / streaming / binary, natural fit.
  • Public, cacheable, resource-shaped APIs, REST maps cleanly.

Where GraphQL wins

  • Many clients with different data needs (web + iOS + Android) from one API.
  • Deeply nested / related data in a single round trip.
  • Rapidly evolving frontends, add fields without new endpoints or versions.
  • Aggregating multiple backends behind one schema (gateway).

Common misconceptions

"GraphQL replaces REST." No, they coexist; many teams use REST for simple resources and GraphQL for complex client-driven reads.

"GraphQL has no caching." It can, via persisted queries and normalized client caches (Apollo, Relay, urql), it's just not free like HTTP caching.

"GraphQL is always faster." It reduces round trips but can hide expensive resolver work; without care it enables costly/deep queries (mitigate with depth limits, query cost analysis, DataLoader batching).

How errors differ

  • REST: the HTTP status code carries meaning, 404, 400, 500.
  • GraphQL: usually returns 200 OK with an errors array in the body, even for partial failures. Clients must inspect the payload, not just the status.

Decision guide

Choose… When…
REST Simple CRUD, public API, heavy caching/CDN needs, file transfer, small team
GraphQL Multiple client types, complex nested data, fast-moving UI, aggregating services
Both Large systems, REST for cacheable resources, GraphQL for client-driven views

Quick takeaways

  • GraphQL = client-specified queries, one endpoint, no over/under-fetching.
  • REST = resource endpoints, easy caching, simpler tooling.
  • The honest answer to "which is better" is it depends on your clients and data shape, not a universal winner.

Maintained by the team at EchoGlobal. Hiring API talent? See our curated lists of Top GraphQL Developers, Top API Developers, and Top Node.js Experts on GitHub, or hire pre-vetted developers in days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment