Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Handbooks  /  GraphQL vs REST
Engineering~9 min readComparison
Head to Head

GraphQL vs REST: who picks the shape of the data?

GraphQLvsREST

REST hands you a menu of fixed dishes; GraphQL hands you the ingredients and lets each client cook exactly the plate it wants. That single difference — server-decided shape vs client-decided shape — cascades into everything else: over-fetching, caching, versioning, and the failure modes each one is prone to.

00

New to this? Start here

Both are ways for an app to ask a server for data. Your phone app needs a user's name, their photo and their last three orders. It has to ask a server. REST and GraphQL are two conventions for how that asking works.

REST gives you a set of fixed addresses, each returning a fixed shape: /users/42 returns the user, /users/42/orders returns the orders. The server decides what each address returns. Want three things? Usually three requests.

GraphQL gives you one address and a query language. You send a request describing exactly the fields you want, across all three things, and get back one response shaped like your request. The client decides what comes back.

That is the whole distinction — server-decided shape versus client-decided shape — and everything below is a consequence of it: how much data you over-fetch, how cacheable responses are, how you version the API, and how each one fails under load.

01

The one distinction that decides everything

REST models your API as a set of resources, each at its own URL (/users/42, /users/42/posts), and the server decides what fields each endpoint returns. GraphQL exposes a single endpoint (/graphql) and a type schema, and the client writes a query saying exactly which fields of which resources it wants — the server assembles precisely that shape in one response.

→ The rule

If the server should own the response shape and you want simple, cacheable, resource-oriented endpoints, REST fits. If many different clients each need a different slice of deeply-related data and you want them to ask for exactly that in one round trip, GraphQL fits.

02

Head to head

DimensionRESTGraphQL
EndpointsMany, one per resourceOne (/graphql), a typed schema behind it
Response shapeFixed by the server per endpointChosen by the client, per query
Over/under-fetchingCommon — fixed payloads, multiple calls to assemble a viewSolved — ask for exactly the fields you need, across resources, at once
HTTP cachingFree — GET + stable URL caches in browsers, CDNs, proxiesHard — single POST endpoint bypasses URL caching; needs app-layer caching
VersioningExplicit — /v2/, breaking changes ship new URLsEvolve the schema — deprecate fields instead of versioning
Typing & introspectionConvention (OpenAPI adds it on)Built-in — a typed schema, introspectable, self-documenting
Error handlingHTTP status codes (404, 500…)Usually HTTP 200 with an errors array; partial data is normal
Server complexityLow — each route is a handlerHigher — resolvers, schema, and the N+1 problem to manage
Classic failure modeThe mobile app makes 6 calls and still over-fetchesOne innocent query fans out into N+1 database hits
03

When to use each

Reach for REST

  • A public API many third parties consume (predictable, cacheable, familiar)
  • Simple, resource-shaped CRUD without deep nesting
  • You want HTTP caching, CDNs and standard status codes for free
  • File uploads/downloads and streaming, which REST handles naturally
  • A small team that doesn't want to run a schema + resolver layer

Reach for GraphQL

  • Many clients (web, iOS, Android) each needing a different data shape
  • Deeply nested, related data assembled per screen (feeds, dashboards)
  • You're tired of shipping a new endpoint every time the UI changes
  • A gateway aggregating several backend services behind one schema
  • Fast-moving product teams that want the client to drive the query
04

The answer is often "REST underneath, GraphQL at the edge"

These aren't mutually exclusive. A very common production shape is REST (or gRPC) between internal services — where simple, cacheable, independently-deployed endpoints shine — with a GraphQL gateway in front, aggregating those services into one client-facing schema so the web and mobile apps get exactly-shaped data in a single round trip. The clients get GraphQL's ergonomics; the backend keeps REST's simplicity and caching. You don't have to pick one for the whole system.

→ The cheap default

Start with REST. It's simpler, its caching is free, and most APIs are resource-shaped enough that it's genuinely the right tool. Reach for GraphQL when you can point at a concrete pain — multiple clients over-fetching, or a screen that needs five REST calls to render — not because it's newer.

05

The caching and N+1 reality nobody mentions in the demo

GraphQL's flexibility has two costs the tutorials skip. First, caching: REST rides on HTTP, so a GET /users/42 is cached for free by the browser, the CDN and any proxy in between. GraphQL clients typically send queries as a POST to one URL, so that layer of free caching mostly evaporates (the spec allows queries over GET, and persisted queries sent by GET are CDN-cacheable) — you rebuild it in the application with persisted queries, a normalized client cache (Apollo, urql), and server-side response caching keyed on the query, not the URL.

Second, the N+1 problem: a query for 50 posts, each with its author, can trigger a naive resolver to run 1 query for the posts and then 50 more for the authors — 51 database hits for one request. The fix is DataLoader, which batches every author lookup in a single tick into one IN (...) query and caches results per request. It's a solved problem — but it's a problem you have to know exists, whereas REST's fixed endpoints rarely surprise you this way.

→ The trade you're actually making

GraphQL moves work from the client (which no longer over-fetches or makes many round trips) onto the server (which now owns schema design, resolver batching and a caching strategy HTTP used to give you for free).

06

A worked scenario: a public weather API vs a social feed app

A public weather API — GET /forecast?city=London — is a textbook REST case: the resource is simple, the response shape is stable, thousands of clients want the same data, and CDN caching a popular city's forecast for a few minutes is a massive, free win. Wrapping that in GraphQL would add a schema, resolvers and a caching headache to solve a problem REST already handles perfectly.

A social app's home feed is the opposite. One screen needs the current user, their feed of posts, each post's author, like count, top comments and each commenter's avatar — five or six related resources, nested, and the iOS app wants slightly different fields than the web app. In REST that's a waterfall of calls or a bespoke /feed endpoint you re-cut every time the design changes. In GraphQL it's one query per client, each asking for exactly its fields — with DataLoader batching the author and comment lookups so "one query" doesn't quietly become N+1 behind the scenes.

→ The pattern generalizes

Stable, cacheable, one-shape-fits-all data → REST. Many clients, deeply nested and varied per screen → GraphQL. Big systems usually have both shapes, which is why "REST services behind a GraphQL gateway" is so common.

The picture

The picture: one screen, two request paths

REST: the server picks the shape client CDNhit = no origin GET /feedserver joins DB1 JOIN query GraphQL: the client picks the shape client POST /graphqlno URL to cache posts1 query, 50 rows author ×501 call per post naive50 SELECTs DataLoader1 WHERE id IN naive 1 + 50 = 51 queries · batched 1 + 1 = 2
The same feed screen both ways. REST puts the shape in a URL the server owns, so a CDN can answer repeat requests without reaching the origin, and the handler can write one JOIN because it knows the whole shape in advance. GraphQL lets the client name the shape, so the server only learns it at request time. Each field’s resolver runs on its own: the author resolver fires once per post, and without batching that is the page’s 51 queries. DataLoader waits until the current tick ends, collects the 50 author ids, and sends one IN (…) query. That gives 2 queries, and one more per extra nesting level.
Trade-offs

Cost and trade-offs: round trips, caching and server load

Here Time is what the client waits for or the server spends. Space is bandwidth, cache or query load. Round-trip figures assume a slow mobile link at 200 ms per round trip, an illustrative number. Server time is ignored.

CaseTimeSpaceWhy
Screen needs 5 resources, REST, one after another5 × 200 ms = 1,000 msEach response is the endpoint’s full shape, used or notEach call waits for an id from the one before. This is the waterfall the page warns about.
Same screen, REST, independent calls in parallel2 dependency levels × 200 ms = 400 msStill over-fetches fieldsParallel calls help only when the next call does not need the previous answer.
Same screen, one GraphQL query1 × 200 ms = 200 msOnly the requested fields cross the wireThe server now runs every resolver, so its latency is your latency.
Feed with comments, naive resolvers1 + 50 + 50 + 150 = 251 queries for 50 posts with 3 comments eachDatabase load grows with list sizes multiplied togetherPosts, then an author per post, comments per post, and a commenter per comment.
Same feed with DataLoader4 queries, one per nesting levelA per-request cache of loaded idsThe number of queries now grows with the query’s depth, not with how many rows come back.
Popular public GET, cached 60 s at the edge1,000 req/s is 60,000 a minute, and the origin sees about 1 per edge location per minuteEdge storage, which costs you nothing to buildNeeds Cache-Control headers. A shared cache will not reuse a response to a request carrying Authorization unless you explicitly mark it cacheable.
GraphQL cachingPersisted queries sent by GET restore URL caching for known queriesA normalized client cache, plus server caches keyed on query and variablesAd-hoc POST queries still miss the CDN. You rebuild the layer REST got for free.
Breaking changeREST: ship /v2 and run both versions until clients moveGraphQL: mark the field @deprecated and keep serving itYou can only remove a GraphQL field once you can see that no client still asks for it, so log field usage.

The table makes the page’s trade concrete. GraphQL turns a 1,000 ms client waterfall into one round trip. It does this by moving the joins into resolvers you must batch, and the caching into layers you must build. REST keeps the server simple and the CDN free, and pays for it in client round trips and over-fetching. A gateway in front of REST services, the page’s common production shape, takes some of each. The client gets the single round trip. The services behind it keep their simple, cacheable endpoints, and the batching problem moves into the gateway’s resolvers, where one team can solve it once.

Watch for

Common mistakes

  • No cost limit on a public GraphQL API

    A client can nest friends { friends { friends { … } } } until one request touches millions of rows. Set a depth limit and a cost budget per query, and paginate every list. For your own apps, accept only persisted queries, a fixed allowlist of known query hashes, so arbitrary queries never run at all.

  • Alerting on HTTP status codes

    GraphQL usually returns 200 with an errors array, and partial data counts as success. A dashboard of 5xx rates stays green while half your resolvers fail. Count entries in errors per operation name, and alert on that.

  • One DataLoader shared across requests

    DataLoader caches every id it loads. Create it once at server start and that cache is shared by every user and never refreshed, so one user can be served another’s stale or private record. Create a new loader per request, in the request context, so its cache lives exactly as long as the request and is thrown away with it.

  • Schema that mirrors the database

    Generating one type per table, with foreign keys as fields, exposes your storage layout to every client and freezes it there. Design types around what screens need, and keep table names and join keys behind the resolvers.

  • Assuming REST caching is automatic

    A GET is cacheable only if the response says so. With no Cache-Control, or with per-user data behind an Authorization header, the CDN passes every request through to the origin. Decide per endpoint what is public, for how long, and what varies by user.

Your call

Which would you pick?

Three situations. Pick the side you'd actually build — the explanation follows.

A mobile client renders a screen from five related resources and is on a slow connection.

A public API served to unknown third parties at high volume, where you must protect the backend from expensive queries.

Someone argues GraphQL is better because "you only fetch the fields you need."

Frequently asked

Quick answers

GraphQL or REST — which should I use?

Decide by who needs to control the response shape. For a simple, public, cacheable API with stable resources, REST is simpler and its HTTP caching is free. For an app with many clients fetching deeply nested, varied data, GraphQL lets each client ask for exactly what it needs in one round trip. Many teams run both: REST for public/simple endpoints, GraphQL as a client-facing gateway.

What problem does GraphQL actually solve?

Over-fetching and under-fetching. A fixed REST endpoint returns a fixed shape, so a mobile screen often gets more fields than it needs, or has to call three endpoints to assemble one view. GraphQL lets the client request exactly the fields it wants, for multiple resources, in a single request.

Why is caching harder with GraphQL?

REST rides on HTTP — a GET to a stable URL is cached for free by browsers, CDNs and proxies. GraphQL usually POSTs every query to one endpoint, so URL-based caching doesn't apply. You recover it at the app layer: persisted queries, a normalized client cache, and DataLoader on the server.

What is the N+1 problem in GraphQL?

A query for a list plus a field on each item that needs its own lookup (50 posts, each with an author) can fire 1 + N queries. The standard fix is DataLoader, which batches all the lookups from one tick into a single query and caches them per request.

▶  Watch it explained

GraphQL vs REST: a fixed menu, or build-your-own?

GraphQL vs REST · Vibe Engines · 2026
Finished this one? 0 / 209 Handbooks done
NextREST vs Webhooks vs SSE Next on the “Networks, APIs and auth” ladder · rung 6 of 9

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Handbooks