Skip to main content

REST vs GraphQL: Why Does GraphQL Exist?

Updated 7 min readMarkdown
Part of seriesExploring GraphQL

Modern applications need to communicate with servers to fetch, create, update and delete data.

Imagine building a developer community application where users can explore events, register for meetups, view speaker profiles and interact with other developers.

The frontend needs data from different resources, such as users, events, speakers and registrations.

REST APIs have traditionally been a popular way to handle this communication. However, as applications became more complex, developers started facing a few challenges when fetching data.

Two common problems are:

  • Over-fetching: Receiving more data than the application actually needs.
  • Under-fetching: Having to make multiple API requests to collect all the data required by a screen.

This is where GraphQL comes into the picture.

GraphQL was developed internally at Facebook in 2012 and publicly open-sourced in 2015. It introduced a different approach to fetching data by allowing clients to specify exactly which fields they need.

But before understanding GraphQL, let's look at how REST works.

How REST APIs Work

REST stands for Representational State Transfer. It is an architectural style used for designing APIs that communicate over HTTP.

In REST, data is generally organised around resources, and each resource is accessed through a URL (endpoint).

For our developer community application, we might have endpoints like these:

HTTP Method Endpoint Purpose
GET /users/1 Fetch user details
GET /users/1/events Fetch a user's registered events
GET /events/101 Fetch a particular event
POST /events Create a new event
PUT /events/101 Update an event
DELETE /events/101 Delete an event

Let's say our frontend needs to display a user's profile.

It sends a request:

GET /users/1

The server might return:

{
  "id": 1,
  "name": "Vaishali",
  "email": "vaishali@example.com",
  "phone": "9876543210",
  "address": "Mumbai"
}

The frontend receives this response and uses the required information to display the profile.

This approach is straightforward and works well for many applications.

However, things can get a little complicated when the frontend needs different combinations of related data.

What Are Over-fetching and Under-fetching?

Let's understand these two problems using the same example.

Over-fetching

Over-fetching happens when an API returns more data than the client actually needs.

Imagine our profile card only displays the user's name.

However, the REST API returns:

{
  "id": 1,
  "name": "Vaishali",
  "email": "vaishali@example.com",
  "phone": "9876543210",
  "address": "Mumbai",
  "createdAt": "2026-01-10"
}

Our UI only needs:

{
  "name": "Vaishali"
}

We receive several additional fields that our UI doesn't even use.

This is called over-fetching.

Under-fetching

Under-fetching happens when a single API request doesn't provide all the data required by the frontend.

Imagine our profile page needs:

  • User name
  • User email
  • Registered event names
  • Event dates

We first request:

GET /users/1

The response contains:

{
  "id": 1,
  "name": "Vaishali",
  "email": "vaishali@example.com"
}

But where are the registered events?

We need another request:

GET /users/1/events

Now we're making multiple requests just to collect the information needed for one screen.

This is an example of under-fetching.

Note: These are common possibilities with REST APIs, not unavoidable limitations. REST endpoints can also be designed to return related data together or support field selection.

How Does GraphQL Approach Data Fetching Differently?

GraphQL is a query language for APIs and a runtime for fulfilling those queries with data.

Unlike traditional REST API designs, GraphQL allows the client to specify exactly which fields it needs.

Let's take our previous example.

We want to display:

  • User name
  • User email
  • Registered event names
  • Event dates

With GraphQL, we can write a single query:

query {
  user(id: "1") {
    name
    email
    events {
      eventName
      date
    }
  }
}

The server can return:

{
  "data": {
    "user": {
      "name": "Vaishali",
      "email": "vaishali@example.com",
      "events": [
        {
          "eventName": "React Meetup",
          "date": "2026-12-10"
        },
        {
          "eventName": "GraphQL Workshop",
          "date": "2026-12-15"
        }
      ]
    }
  }
}

Notice something interesting?

We requested only the fields we needed, and the response follows the structure of our query.

We also didn't need to make separate frontend requests for the user and their events.

That's one of the main advantages of GraphQL: the client gets more control over the shape of the response.

One important thing to understand is that a single GraphQL request doesn't necessarily mean a single database query.

Behind the scenes, the server might still fetch information from multiple tables, databases or other data sources to prepare the response.

GraphQL doesn't require a completely different database structure either. It works as a layer between the client and the underlying data sources.

We'll explore how this actually works in the next blog.

REST vs GraphQL: A Practical Comparison

Let's quickly compare both approaches.

Feature REST GraphQL
API structure Resource-based endpoints Commonly a single endpoint
Data fetching Response generally defined by the endpoint Client specifies requested fields
Over-fetching Can occur Reduced through field selection
Under-fetching May require multiple requests Related data can be requested together
Response structure Defined by the server endpoint Follows the requested query structure
Caching Well-supported HTTP caching Requires additional caching strategies
Versioning Often uses URL versioning Can evolve through schema changes

Neither approach is perfect for every situation.

GraphQL also introduces challenges, such as query complexity, caching, authorization and the N+1 problem.

Choosing between them depends on the application's requirements.

When Should You Use GraphQL or REST?

GraphQL can be useful when:

  • An application has complex relationships between data.
  • Different screens require different combinations of fields.
  • Multiple clients, such as web and mobile applications, consume the same API.
  • Developers need more flexibility when fetching data.

For example, our developer community platform might have different screens for users, event organisers and speakers. Each screen needs a different combination of related data.

GraphQL can make handling these requirements easier.

REST can be a better choice when:

  • The application has simple CRUD operations.
  • Resources have straightforward endpoint structures.
  • Standard HTTP caching is important.
  • The team already has a well-established REST architecture.

For example, a simple blog application with endpoints to retrieve posts, create posts and delete posts might not need the additional complexity of GraphQL.

Sometimes, keeping things simple is the best architectural decision.

What I Learned

While exploring REST and GraphQL, one thing that stood out to me was that GraphQL isn't about replacing REST everywhere.

Both approaches solve the problem of communication between applications and servers, but they approach data fetching differently.

REST structures API access around resources and endpoints, whereas GraphQL allows clients to describe the data they need through queries.

I also learned that making one GraphQL request doesn't necessarily mean executing just one database query.

This was my first step in exploring GraphQL beyond just writing queries and mutations.

There's still a lot more to learn, and I'm excited to experiment with implementations and contribute to the open-source ecosystem.

In the next blog, I'll explore the building blocks of GraphQL, including:

  • Schema design and GraphQL types
  • Queries and mutations
  • Resolvers and context
  • The N+1 problem and why it matters for GraphQL performance

Part of my Exploring GraphQL learning journey.

16 views

JJustOneCX21h ago

Teams usually move to GraphQL to cut over-fetching across several screens. The cost shows up in caching and rate limiting, which are harder per query. Did you cover those?

Yeah sure, in upcoming blogs I will cover this.

Insightful content

Thankss

Exploring GraphQL

Part 1 of 1

A learning journey exploring GraphQL from the basics to advanced concepts. Understanding how GraphQL works, experimenting with schemas, types, queries, mutations, resolvers, and exploring real-world use cases along the way.