Course contentsShow
← System Design
Lesson 1911 of 1,91945. API Design and VersioningFree lesson

GraphQL vs REST: Tradeoffs

Comparing over-fetching, under-fetching, multiple round-trips in REST versus GraphQL's single endpoint and payload efficiency.

GraphQL vs REST: Tradeoffs

What you'll learn: How GraphQL and REST differ in handling data fetching efficiency, round-trips, and client-server communication patterns.

The Core Comparison

REST and GraphQL solve the same problem—client-server communication—but with different philosophies. REST's resource-oriented approach often leads to over-fetching (getting more data than needed) and under-fetching (not getting enough, requiring additional requests). GraphQL addresses these issues through its query-driven model, but introduces its own complexities.

REST's Multi-Request Problem

In REST, fetching related resources typically requires multiple round-trips:

GET /users/123           → Returns user with post IDs
GET /posts/456           → Fetch first post
GET /posts/457           → Fetch second post
GET /users/789           → Fetch author of another post

Each endpoint returns a fixed structure. If you only need usernames but get full user objects with addresses and timestamps, that's over-fetching. If you need posts and their comments, that's multiple round-trips.

GraphQL's Single-Endpoint Efficiency

GraphQL lets clients specify exactly what they need in one request:

query {
  user(id: 123) {
    name
    posts {
      title
      comments { author }
    }
  }
}

One query, one round-trip, precisely the data needed—no over-fetching or under-fetching.

The Tradeoffs

GraphQL wins on:

  • Payload efficiency (no unwanted fields)
  • Reduced round-trips (nested fetching)
  • Client flexibility (evolve UI without backend changes)

REST wins on:

  • HTTP caching (GET requests cache naturally)
  • Simplicity (standard HTTP semantics)
  • Tooling maturity (widespread support)
  • Predictable performance (fixed queries)

Key Takeaway: GraphQL excels when clients need flexible, precise data fetching with minimal round-trips, while REST shines for cacheable, predictable resource access with simpler infrastructure—choose based on your client diversity and data access patterns.