Archprimer
TradeoffIntermediate 8 min read

REST vs GraphQL

REST exposes fixed resource endpoints prone to over/under-fetching; GraphQL offers one flexible query endpoint at the cost of caching and N+1 complexity.

apirestgraphqlhttp

By Ratish Jain · Updated

Diagram with 5 components: Client, REST API, GraphQL, Services + DB, Resolvers + DB. Connections: Client → REST API (GET /users); Client → GraphQL (query{...}); REST API → Services + DB (fixed); GraphQL → Resolvers + DB (resolve).
ClientGatewayService
Multiple fixed endpoints versus a single flexible query graph.

The Decision

Both are ways for clients to talk to a backend over HTTP. REST models the world as resources at fixed URLs (/users/1, /users/1/posts), each returning a predetermined shape. It is simple, cache-friendly, and universally understood — but clients often over-fetch fields they do not need or under-fetch and make many round trips.

GraphQL exposes a single endpoint where the client sends a query describing exactly the fields it wants, in one round trip. That precision shifts complexity to the server: caching is harder, and naive resolvers create N+1 query storms.

So it depends on whether you value REST's simplicity and HTTP-native caching, or GraphQL's flexible, client-driven data fetching.

Side by Side

RESTGraphQL
EndpointsMany, one per resourceSingle /graphql endpoint
Data shapeServer-defined, fixedClient-specified per query
FetchingOver/under-fetch commonExactly requested fields
Round tripsOften multipleUsually one
CachingEasy via HTTP + URLsHarder; needs app-level cache
VersioningExplicit /v1, /v2Evolve schema, deprecate fields
Main riskEndpoint sprawlN+1 resolvers, query cost

GraphQL Strengths & Weaknesses

Pros
  • Clients fetch exactly the data they need in a single request
  • Strongly typed schema with introspection and great tooling
  • Evolves without version bumps; ideal for diverse mobile/web clients
Cons
  • HTTP caching breaks; needs DataLoader and app-level caching
  • Unbounded queries risk N+1 and expensive server work
  • More server complexity and a learning curve than plain REST

Decision Guide

Decision Guide

Choose REST for simple, resource-oriented, public or cacheable APIs where CDN/HTTP caching matters and clients are uniform. Choose GraphQL when many client types need different data shapes, you want to aggregate multiple backends, and you can invest in query cost limits, DataLoader batching, and monitoring.

Real-World Examples

GitHub
Offers both a REST v3 and a GraphQL v4 API
Facebook
Created GraphQL to power data-hungry mobile apps
Shopify
Pushes GraphQL as the primary storefront/admin API
Stripe / Twilio
Remain REST-first for simplicity and caching

Interview Questions

What is the N+1 problem in GraphQL and how do you fix it?

A query for a list plus a nested field can trigger one DB call per item. Batching tools like DataLoader coalesce those into a single query per level, eliminating the N+1 explosion.

Why is caching harder in GraphQL than REST?

REST responses map to stable URLs and HTTP verbs, so CDNs and browsers cache them for free. GraphQL uses one POST endpoint with varying query bodies, so you must cache at the field/entity level in the app instead.

60-Second Revision
  • →REST = fixed endpoints, server-defined shapes, easy HTTP caching.
  • →GraphQL = one endpoint, client picks fields, one round trip.
  • →REST suffers over/under-fetching; GraphQL fixes it.
  • →GraphQL trades away caching simplicity and risks N+1.
  • →REST for cacheable/uniform APIs; GraphQL for flexible multi-client needs.

Related

Everything on Archprimer is connected — follow the graph.