GraphQL vs REST API: Architecture Comparison, Payload Size, and Benchmarks

Compare GraphQL and REST APIs. Analyze over-fetching, under-fetching, N+1 query problems, caching, and payload sizes with practical code benchmarks.

When choosing between an http api using REST and a GraphQL schema, developers weigh bandwidth efficiency against caching simplicity. REST treats URLs as resources; GraphQL treats the graph as a queryable schema over a single POST endpoint.

Core Comparison Matrix

  • Payload Size: GraphQL eliminates over-fetching by letting the client request only { id, name }. REST endpoints often return 40+ fields per object.
  • HTTP Caching: REST leverages standard browser and CDN caching out-of-the-box via URL and ETag. GraphQL requires specialized client-side cache stores (Apollo/Relay).
  • Network Roundtrips: REST can suffer from under-fetching (requiring 3 separate calls for user, orders, and addresses). GraphQL resolves nested entities in a single request.