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.
By Ratish Jain · Updated
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
| REST | GraphQL | |
|---|---|---|
| Endpoints | Many, one per resource | Single /graphql endpoint |
| Data shape | Server-defined, fixed | Client-specified per query |
| Fetching | Over/under-fetch common | Exactly requested fields |
| Round trips | Often multiple | Usually one |
| Caching | Easy via HTTP + URLs | Harder; needs app-level cache |
| Versioning | Explicit /v1, /v2 | Evolve schema, deprecate fields |
| Main risk | Endpoint sprawl | N+1 resolvers, query cost |
GraphQL Strengths & Weaknesses
- 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
- 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
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
- 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
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.
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.
- →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.