Nguyen Le Phong

GraphQL or REST? Start With Who Shapes the Data

REST gives you resources and HTTP caching almost for free.

Say a product card on your home screen needs one more field. Then a count of unread comments. Then a stock badge that lives in a different service. The frontend work takes an afternoon. The REST response, though, was shaped for last quarter's screen, so now someone has to decide: add fields to /products/42, create a new endpoint, or let the app call three endpoints and stitch the results together. A small card has turned into a question about who owns the API.

Engineers gather at a whiteboard covered in API flow diagrams, talking through who should change the contract for a small UI card.
A one-field change on a screen can open a bigger question: who decides the shape of the data?

That's how most GraphQL vs. REST debates start in real life. One side of the system wants data in a shape the other side didn't plan for. This post covers what each style is built for, where each one hides its costs, and a few questions that usually settle the choice for a given team.

What REST is built for

REST comes from Roy Fielding's 2000 dissertation, and its center of gravity is the resource: a product, an order, a user, each with its own URL and a small set of standard methods. One of its constraints is caching. Fielding writes that responses must be "implicitly or explicitly labeled as cacheable or non-cacheable," so that a client can reuse a response for later, equivalent requests (Fielding, chapter 5).

That design pays off every day. The URL is a natural cache key, so browsers, proxies and CDNs help you without extra code. Status codes, access logs, per-endpoint rate limits and dashboards all line up with how HTTP already works. You can look at an endpoint and guess what it's for. A small team with a few clients, clear resources and fairly stable screens can go a very long way with this.

Fielding also named the cost, right there in the same chapter: "a uniform interface degrades efficiency, since information is transferred in a standardized form rather than one which is specific to an application's needs." Today we'd call that over-fetching and under-fetching. REST was tuned for "large-grain hypermedia data transfer," and a dense mobile screen that needs bits from five resources is a different job.

What GraphQL is built for

GraphQL starts from the other end. The client describes the shape it needs, and the server fills it in. Compare the two ways of loading that product card:

# REST: three round trips, each shaped by its own endpoint
GET /products/42
GET /products/42/comments?unread=true
GET /inventory/42/status

# GraphQL: one request, shaped by the screen
query ProductCard($id: ID!) {
  product(id: $id) {
    name
    price
    unreadCommentCount
    stockStatus
  }
}

The mobile app can drop price if the screen doesn't show it. The web dashboard can ask for related objects in the same request. Nobody has to open a ticket for a new endpoint every time a screen changes.

GraphQL also changes how an API grows. The official guide explains that because GraphQL "only returns the data that's explicitly requested," new types and fields can be added "without creating a breaking change," which is why many teams run a versionless API (Schema Design). When a field needs to go, you mark it with the built-in @deprecated directive and watch usage drop before removing it:

type Product {
  stock: Int @deprecated(reason: "Use stockStatus.")
  stockStatus: StockStatus
}

Where the cost moves

Flexibility never makes cost disappear. It moves it. With REST, the contract is spread across many endpoints, and each one can be tuned, cached and monitored as a known shape. With GraphQL, it concentrates in the schema, the resolvers and the guardrails around them. Four places show it most clearly.

Resolvers that call the database in a loop

Each GraphQL field has its own small resolver function. The docs warn that, done naively, this makes a service "very chatty": one call loads a list, then one more call per item loads its children. That's the N+1 problem, and the usual fix is batching with a tool like DataLoader, which collects the lookups made during one tick and sends them as a single query (GraphQL performance).

Caching takes deliberate work

GraphQL servers accept POST by default, while HTTP caches and CDNs treat GET as the cacheable method. The spec for GraphQL over HTTP also allows GET for queries, and long queries can be sent as a hash using persisted queries or trusted documents, which lets a CDN cache them (GraphQL performance). It works well. It's also setup you get for free with REST URLs.

One query can ask for a lot

A client can nest lists inside lists and request far more work than any screen needs, by accident or on purpose. The official security guide recommends limiting depth, limiting the number of top-level fields and aliases, and scoring each request with query complexity analysis (GraphQL security). GitHub's public GraphQL API is a good real-world example: every connection must set first or last between 1 and 100, a single call can't request more than 500,000 nodes, and users get 5,000 points per hour, where points come from the estimated cost of each query (GitHub rate limits).

Errors hide in a 200

A GraphQL response can carry data and an errors list at the same time. The spec says that when field errors happen during execution, the errors entry should list them, while the rest of the data still comes back (GraphQL spec, Response Format). And the official guide to serving GraphQL says a response with non-null data should get a 2xx status "even if the response includes errors," since HTTP has no status code for partial success (Serving over HTTP). A dashboard that only counts 5xx can stay green while one field fails on every request, so log and alert on the errors list per operation.

A team studies performance dashboards and a resolver flow diagram, tracing how one GraphQL query fans out into many backend calls.
One short query can fan out into dozens of backend calls. Batching, cost limits and per-operation metrics keep that visible.

Team shape matters as much as the tech

REST tends to fit when backend teams own domain APIs and clients have fairly stable needs. GraphQL tends to fit when several clients iterate fast and someone is willing to treat the schema as a product: careful field names, deprecations instead of breaking changes, authorization tested per field, and an eye on the queries clients really send. A schema without an owner turns into a shared junk drawer in a few months.

Sam Newman's Backends for Frontends pattern is a useful frame here. A BFF is a server-side component for one user experience, and it's "typically maintained by the same team as the user interface," so that team can change the API as the screen changes (Backends For Frontends). Many teams build that layer with GraphQL, and plenty build it with plain REST. The ownership question is the same either way.

The security guide adds one practical split. Trusted documents, an allowlist of known queries, only work for first-party clients, because you can't know a third-party client's queries ahead of time (GraphQL security). If your main consumers are outside developers, you'll lean on cost limits and rate limits instead, which may be one reason many public APIs stay REST.

You can use both

Plenty of mature systems run both. REST handles webhooks, file uploads, public APIs and service-to-service calls, where a stable resource and HTTP caching are exactly right. GraphQL sits at the edge for product screens that need to compose data from several domains. The useful decision is where each style removes friction without hiding operational cost.

A product team compares a client dashboard with a backend flow diagram to decide where REST and GraphQL meet in one system.
A common split: REST for plain resource contracts, GraphQL where screens need to combine data from many places.
If this is your situation It usually leans toward
Public API for outside developers REST, or GraphQL with strict cost limits like GitHub's
One web app, stable screens, small team REST
Web, iOS and Android needing different shapes of the same data GraphQL or a BFF per experience
Heavy CDN caching of read traffic REST, or GraphQL with persisted queries over GET
Webhooks, file uploads, service-to-service calls REST
Unclear domain boundaries between teams Neither will fix it. Sort out ownership first.

Let the pain decide

API style should follow how your teams work together. If the main pain is fuzzy domain boundaries, GraphQL won't save you, it'll give the fuzziness a nicer syntax. If the main pain is clients waiting on endless endpoint tweaks, sticking to REST purity gets expensive. If the main pain is debugging production, pick whichever approach gives you better logs, clearer ownership and visible failures.

Both styles are promises made across a boundary. The question worth asking is which promise your team can keep with less confusion. For the next layer out, see API Gateway Patterns, and for making write calls safe to retry in either style, Designing Idempotent APIs.

Try this week

  • Pick your busiest screen. Count how many API calls it makes and how many returned fields it never shows.
  • On GraphQL already? Turn on a depth limit, log the estimated cost of each operation, and check your slowest query for N+1 lookups.
  • Add an alert on the errors list in GraphQL responses, separate from HTTP status codes.
  • Write down who owns each schema or endpoint group, and who approves a breaking change.
What did you think?

Frequently asked questions

Is GraphQL faster than REST?
Not by default. GraphQL can cut round trips and unused fields, but one query can fan out into many resolver calls. Without batching (for example with DataLoader), caching and cost limits, a GraphQL request can be slower and heavier than the REST calls it replaced.
Can you cache GraphQL responses like REST?
Yes, with extra setup. GraphQL servers accept POST by default, while HTTP caches and CDNs treat GET as the cacheable method. The GraphQL over HTTP spec allows GET for queries, and persisted queries or trusted documents let clients send a short hash so a CDN can cache the response. REST URLs get this behavior without the extra work.
Does GraphQL need API versioning?
Usually not. Because clients only receive the fields they ask for, you can add types and fields without breaking anyone. To retire a field, mark it with the @deprecated directive, watch its usage drop, then remove it.
How do you stop expensive GraphQL queries?
Limit query depth and the number of top-level fields and aliases, score requests with query complexity analysis, and rate-limit by cost. GitHub's public API, for example, requires first or last between 1 and 100 on every connection, caps a call at 500,000 nodes and gives users 5,000 points per hour.
Should I use GraphQL and REST together?
Many systems do. REST suits webhooks, file uploads, public APIs and service-to-service calls. GraphQL suits product screens that combine data from several domains. Decide per boundary, and make sure each one has a clear owner.