Skip to content
← Web & IT

/knowledge/notes/rest-vs-graphql

Concept note · Web & IT

REST vs GraphQL

API Design

Studied
Web Information TechnologyINFO30005
When
2021 S1
Applied in
Snacks in a Van
Read / Refreshed
~5 min read2026-10-15

REST and GraphQL are two architectures for fetching data from servers. REST uses multiple endpoints; GraphQL uses one query language. This note covers the tradeoffs and when each makes sense.

01

The idea

In REST, you fetch entire resources (a user, a post) and get all their fields. If you need related data (a user's posts, or a post's comments), you fetch a separate resource. This creates N+1 problems and wasteful over-fetching. GraphQL lets you declare exactly which fields you want across related resources in one query. The server returns only what you asked for.

The tradeoff is complexity. REST is simple to implement and cache. GraphQL requires query parsing and validation, and caching is trickier. For mobile clients with limited bandwidth, GraphQL is often better. For simple, server-driven APIs, REST is often simpler.

02

The maths

Let n be the number of related resources you need to fetch.

  • REST: Requires n HTTP requests, one per resource. Total bytes transferred includes unused fields from each response.
  • GraphQL: Requires 1 HTTP request. Total bytes transferred is only what was requested.

Latency savings are largest when n is large and each resource has many unused fields. If n=1 and all fields are needed, REST and GraphQL are equivalent.

03

Try it

The widget shows a REST response (multiple requests, waterfall) and a GraphQL response (single query). Check the fields you want and see the difference. Larger selections make GraphQL's advantage clearer.

REST (waterfall)
GET /api/users/1
→ round trip 1
GET /api/users/1/posts
→ round trip 2 (waits for the first)
GraphQL (single)
POST /graphql
→ 1 round trip (nested fields resolved on the server)
3 fields selected
Comparison of REST and GraphQL for fetching user data. Check fields to see latency and data size differences.
  • REST requires multiple round trips; GraphQL needs one.
  • Checking more fields makes the over-fetching in REST more obvious.
  • Cache headers work differently: REST is header-based; GraphQL needs app-level caching.

04

Where I used it

05

Easy to get wrong

06

Sources

Compared across projects (2022-2026).