What Is GraphQL?
GraphQL is a query language for APIs and a server-side runtime for executing those queries, developed at Facebook in 2012 and open-sourced in 2015, that allows clients to request exactly the data they need and nothing more.
Whereas REST APIs present fixed endpoints giving predetermined data structures and clients must work with what those endpoints provide, GraphQL gives a single endpoint that clients use to submit typed queries that specify exactly what data they need. The server then answers with a JSON object made precisely to match the query.
Over-fetching and under-fetching that plague REST are eliminated by this architecture and the number of network round-trips needed to build complex views is reduced. Front-end teams get independent control over what data they need for their views without any requirement that back-end code change.
In 2012, engineers at Facebook were dealing with a problem that had become common at large technology companies: their API was built for desktop browsers, but mobile was growing fast.
Much less data was needed for the mobile app (only a user's name and profile photo). The existing API gave back a full user object with dozens of fields and each request sent kilobytes of unnecessary data over slow mobile networks.
Meanwhile, some features needed collecting data from three or four different REST endpoints and that meant the app had to send several sequential requests before it could show a screen.
Facebook's team built a solution called GraphQL. It is a query language for APIs that allows the client to say precisely what it needs and gives the server a way to return exactly that.
In 2015, Facebook open-sourced GraphQL. By 2016, GitHub had migrated its public developer API to GraphQL. Today, it is used at scale at Shopify, Twitter, Airbnb, Netflix, and hundreds of other companies. It has become one of the most consequential shifts in API design in the last decade.
The 2023 State of JavaScript survey showed that GraphQL adoption among JavaScript developers had climbed to about 29 percent and this was up from 20 percent three years before.
The 2023 annual GraphQL Foundation landscape report counted over 20,000 open-source projects on GitHub tagged with GraphQL. That shows an ecosystem that has grown from experimental to mainstream.
When teams build products for mobile, web and third-party integrations simultaneously, GraphQL has moved from a curiosity to a standard tool in the professional API designer's toolkit.
The Problems GraphQL Solves
To understand what GraphQL does, you first need to understand what REST does wrong - or more precisely, where REST's design creates friction at scale.
Over-Fetching
Over-fetching occurs when an API endpoint returns more data than the client needs.
Consider a REST endpoint for a user profile: GET /users/123
A typical response might include:
{ "id": 123, "name": "Sarah Chen", "email": "sarah@example.com", "bio": "Software engineer...", "avatar_url": "https://...", "follower_count": 1402, "following_count": 387, "post_count": 89, "created_at": "2019-03-14", "location": "San Francisco", "website": "https://...", "verified":
false, ... }A mobile app that only needs to display a name and avatar in a list view must still download the entire object.
At scale (millions of users making dozens of requests per session) this is a meaningful performance and bandwidth cost.
Internal cases documented by Netflix's API team showed that REST responses held 10x as many fields as any single client used appeared in Netflix's internal records.
On constrained mobile networks common across Asia and Latin America (two of the fastest-growing markets for digital services) this represents both user experience degradation and real monetary cost to users on metered data plans.
Under-Fetching
Under-fetching happens when one endpoint does not send back enough data, forcing the client to make several requests to pull together what it needs.
Building a social media feed might require:
GET /feed- returns a list of post IDsGET /posts/456- get the post contentGET /users/123- get the post author's name and avatarGET /posts/456/comments?limit=3- get preview comments
Four round trips are needed before the feed renders and each brings its own network latency. A fast desktop connection makes this inconvenient. On a slow mobile network or poor cellular signal, it is what separates a good from a terrible user experience.
Akamai researchers in 2017 showed that a 100-millisecond delay in how fast a website loads can cut conversion rates by 7 percent. Cascading latency from many REST round trips is not just a technical nuisance for e-commerce and content platforms. It has measurable effects on revenue as well.
The N+1 Problem
A specific variant of under-fetching is the N+1 problem: to display a list of N posts with their authors, you make 1 request for the posts, then N additional requests for each author. If you're displaying 20 posts, that's 21 API calls for one screen.
GraphQL is designed to eliminate all three of these problems through a fundamentally different approach to data fetching.
How GraphQL Works
GraphQL exposes a single endpoint - typically something like /graphql - that accepts queries written in the GraphQL query language. The client specifies exactly what fields it wants, and the server returns exactly those fields, nothing more.
Queries
When a GraphQL query asks for just name and avatar for a user profile, it looks like this.
query {
user(id: "123") {
name
avatarUrl
}
}The server response:
{
"data": {
"user": {
"name": "Sarah Chen",
"avatarUrl": "https://..."
}
}
}Only the requested fields are returned. The same endpoint can serve a desktop app that needs more fields:
query {
user(id: "123") {
name
email
bio
followerCount
postCount
location
}
}Both clients use the same endpoint, the same server code, and the same schema - they simply ask for different data.
Nested Queries: Solving the N+1 Problem
GraphQL allows you to request related data in a single query:
query {
feed {
posts {
id
content
createdAt
author {
name
avatarUrl
}
comments(limit: 3) {
text
author {
name
}
}
}
}
}What would have required 20+ REST requests now requires one GraphQL query.
The server resolves all the nested relationships internally and returns a single response.
Mutations
While queries read data, mutations write it. A mutation to create a new post:
mutation {
createPost(input: {
content: "GraphQL changed how I think about APIs"
tags: ["graphql", "api-design"]
}) {
id
content
createdAt
}
}The mutation response includes the newly created post's data - the fields the client requested - so the client doesn't need a subsequent read operation to get the created object's ID.
Subscriptions
Subscriptions enable real-time updates. A client subscribes to an event and receives data pushed from the server when that event occurs:
subscription {
newComment(postId: "789") {
text
author {
name
avatarUrl
}
createdAt
}
}The server sends data to the client each time a new comment is posted to that post. Subscriptions are typically implemented over WebSockets.
The Schema: GraphQL's Type System
One of GraphQL's most powerful features is its strongly typed schema. The schema defines every type of data the API can return and every operation it supports. It acts as a contract between client and server and as self-documenting API documentation.
A simplified schema for a blogging platform:
type User {
id: ID!
name: String!
email: String!
posts: [Post!]!
}
type Post {
id: ID!
title: String!
content: String!
author: User!
comments: [Comment!]!
createdAt: String!
}
type Comment {
id: ID!
text: String!
author: User!
}
type Query {
user(id: ID!): User
post(id: ID!): Post
feed: [Post!]!
}
type Mutation {
createPost(input: CreatePostInput!): Post!
}The ! denotes non-nullable fields.
The schema is introspectable. Tools like GraphiQL and Apollo Studio let developers explore the schema interactively, see what queries are possible and test them without reading documentation.
The introspection capability is particularly valuable for teams with many developers. When a frontend engineer wants to know what fields are available on the User type, they can query the schema itself rather than reading documentation that may be stale.
Lee Byron, one of GraphQL's co-creators at Facebook, described this as treating the API as a "living document" - the schema is always authoritative because the server itself can be queried for its own capabilities (Byron, 2015).
GraphQL vs. REST: A Direct Comparison
| Dimension | REST | GraphQL |
|---|---|---|
| Endpoints | Multiple (one per resource) | Single endpoint |
| Data shape | Server-defined | Client-defined |
| Over-fetching | Common | Eliminated |
| Under-fetching | Common | Eliminated |
| Versioning | URL versioning (/v1/, /v2/) | Schema evolution without versioning |
| Caching | HTTP caching works natively | Requires custom caching (Apollo, etc.) |
| Error handling | HTTP status codes | Application-level errors in response |
| Tooling maturity | Very mature | Rapidly maturing |
| Learning curve | Low | Moderate |
| File uploads | Native | Requires workarounds |
| Real-time | Requires SSE or WebSockets manually | Subscriptions built into spec |
| Type safety | Optional (OpenAPI/Swagger) | Built into spec |
| Schema documentation | External (Swagger, Postman) | Introspectable from the API itself |
Where REST Wins
REST is not being replaced by GraphQL across the board. REST genuinely works better in several situations:
Simple CRUD APIs. When your API consists only of create-read-update-delete operations and your clients are all alike, REST's simplicity gives it an advantage. The flexibility of GraphQL is worth most when you have clients that are different and have different needs.
HTTP caching: REST responses can be cached at the network level using HTTP cache headers, CDNs, and browser caches. This is extremely valuable for read-heavy APIs with large audiences.
Most GraphQL queries go out as POST requests whose body changes with every query, so standard HTTP caches cannot store them. Teams can work around that using persisted queries and GET requests, though doing so adds extra moving parts.
Public APIs for unknown consumers: When you're building a public API and don't know who will use it or how, REST's simplicity and familiarity lower the adoption barrier. Many developers already understand REST; GraphQL requires learning the query language and tooling.
File uploads and binary data. GraphQL deals with text data well but was not built to handle file uploads or binary streams. Managing them takes multipart form data extensions that bring extra complexity.
Team familiarity. REST has been the main API approach for 20 years and most developers have strong REST experience. GraphQL expertise is less universal.
Where GraphQL Wins
Multiple client types: A mobile app, web app, and third-party integration that all need the same data in different shapes benefit enormously from GraphQL's flexibility. One API serves all clients without multiple versions or field proliferation.
Rapid front-end iteration. Front-end teams can include new fields in their queries without having to coordinate with back-end engineers to change endpoint responses. That gives a large reduction in the overhead of cross-team coordination.
API aggregation: GraphQL is excellent for building a unified API layer on top of multiple backend services. Clients query a single GraphQL API; the GraphQL server fetches data from microservices, databases, and third-party APIs and composes the response.
Developer experience. The introspectable schema, in-browser IDE tools and type safety create a development experience that REST, with its often-inconsistent documentation, rarely matches.
Reducing mobile data usage. Mobile apps where bandwidth and battery count should request only the fields needed and that cuts both. After moving to GraphQL, GitHub said there were large payload reductions.
How GraphQL Is Used at Scale
GitHub
In 2016, GitHub launched its GraphQL API (v4) and became the most prominent early adopter outside Facebook. The company said that REST had fixed endpoints that made it difficult to meet the varied needs of its developer community. It also sent too much data through too many endpoints. Adding new fields required versioning.
Kyle Daigle, then GitHub's director of ecosystem engineering, noted in the 2016 launch announcement that the GraphQL API returned "just the data you request, which is great for the varying needs of mobile clients." GitHub's GraphQL API covers repositories, pull requests, issues, commits, and virtually every other GitHub entity.
GitHub now lets third-party tools that integrate with it ask for exactly the data they need. That is a big boost for IDE integrations and CI/CD tooling that require only small parts of what is in GitHub's data model.
Shopify
Shopify uses GraphQL as its primary API for both the Storefront API (used by themes and headless commerce frontends) and the Admin API (used by app developers).
Shopify serves millions of merchant stores and as many third-party app integrations; serving them all through REST would have required proliferating endpoints or sending massive over-fetched responses to mobile-first storefronts.
By 2022, Shopify's GraphQL Admin API was the recommended route for developing new apps and the company put documentation and tooling resources into it proportionately. Query flexibility and schema-driven development were the main reasons the company gave for the change.
Meta
Facebook and Instagram continue to use GraphQL internally at a scale no other organization approaches. Facebook's mobile app has used GraphQL since 2012; the query language was refined over three years of internal use before being published.
Meta's experience demonstrates GraphQL's viability at extreme scale - billions of queries per day.
Nick Schrock, another co-creator of GraphQL at Facebook, described the internal development process as solving "real problems at massive scale before we ever wrote a specification" (Schrock, 2015).
GraphQL comes from a production-first lineage that sets it apart from many API standards that were designed theoretically first and only later tested against the complexity of production.
Twitter / X
Between 2020 and 2023, Twitter moved parts of its API over to GraphQL during its major architecture rebuilds.
Efforts to cut over-fetching from its legacy REST endpoints were documented in the platform's "Twitter API v2" docs as moves to reduce over-fetching. Researchers and data consumers who downloaded whole tweet objects to get a single field saw this problem most clearly.
Common Misconceptions About GraphQL
"GraphQL is always faster than REST." That is not necessarily true. If not put together with data loader patterns, the resolver architecture of GraphQL can bring in N+1 problems on the server side. Real benefits come to the client side for performance but server efficiency needs attention.
"GraphQL replaces REST completely." No. Many use cases still make REST the better choice. Public REST APIs continue to be used most places for simplicity and both REST and GraphQL are mixed in most modern systems, with GraphQL for internal use or mobile clients.
"GraphQL is only for React applications." Any language or framework can use GraphQL. Mature GraphQL client libraries exist for Python, Ruby, Java, Go, Swift, Kotlin and almost every other language. The system is not tied to the JavaScript ecosystem.
"GraphQL has no versioning problems." By letting schema evolution that adds fields without breaking existing queries and reducing the need for major version bumps, GraphQL does cut down on what it takes to version a schema. Fields can still be removed or types changed and that needs deprecation strategies as well as coordination.
"GraphQL is always more complex to implement." Simple use cases make that true and REST gets off to a quicker start. When the scenario becomes complex and multi-client though, even if the learning curve at first is steep, GraphQL most often brings down long-term complexity.
Getting Started with GraphQL
For those evaluating whether to adopt GraphQL, a practical starting point:
Identify your pain points: Are multiple client types consuming your API with different data needs? Are you making many round trips? Is over-fetching hurting mobile performance? If yes to any of these, GraphQL may help.
Start with one service: Rather than migrating an entire REST API, introduce GraphQL for one domain (e.g., a user profile service or a product catalog) and observe the developer experience improvement.
Use established tooling: Apollo Server (Node.js), Strawberry or Ariadne (Python), graphql-ruby (Rails), and gqlgen (Go) are mature, well-documented implementations.
Implement DataLoader from the start: The N+1 problem on the server side is real. Facebook's DataLoader pattern (batching and caching resolver calls) should be implemented as a foundational pattern, not retrofitted later.
Consider GraphQL Federation for microservices: If you have multiple services, Apollo Federation allows multiple teams to build and deploy their own GraphQL schemas that are composed into a single unified API. This is how large organizations (including Airbnb and Netflix) use GraphQL across teams.
GraphQL does not solve every API design problem, yet it excels at the jobs it was built for: flexible client-driven queries, cutting out over-fetching and under-fetching and putting one unified API layer in front of varied clients. Knowing when it helps and when it does not is the skill that counts.
GraphQL Performance Considerations
"GraphQL is not a replacement for REST. It is a different tool with a different design center. REST is optimized for simplicity and cacheability. GraphQL is optimized for client flexibility and developer experience at the cost of more complex server-side work."
Lee Byron, one of GraphQL's original creators
Performance in GraphQL is more nuanced than in REST because the flexibility that gives it power also brings new challenges for the server.
The N+1 problem (server-side): When resolving a list of posts and their authors, a naive GraphQL implementation issues one database query for the posts and then N separate queries for each author - the N+1 pattern. For a page of 20 posts, that's 21 database queries.
The standard solution is DataLoader, which batches all author lookups from a single resolver execution into a single database query using a collect-and-batch pattern.
Query depth and complexity: Because clients can request arbitrarily nested data, a malicious or naive client could construct a deeply nested query that creates massive server load. Production GraphQL APIs typically implement:
- Depth limiting: Rejecting queries nested deeper than a threshold (e.g., 7 levels)
- Complexity scoring: Assigning cost scores to fields and rejecting queries that exceed a complexity budget
- Query whitelisting (persisted queries): Only allowing pre-approved query shapes, which also enables caching
Caching strategy: Unlike REST, where a GET /posts/123 response can be cached by URL, GraphQL's single endpoint and variable query bodies require custom caching. Common approaches:
- Response caching: Cache the full query response keyed by query + variables hash (Apollo's default)
- Normalized caching: Cache individual objects by ID and reconstruct responses from the cache (Apollo Client's default on the frontend)
- Persisted queries with CDN caching: Convert POST queries to GET requests with a pre-registered query ID, enabling CDN caching
There is a real cost to caching complexity. Where caching is critical for performance (high-traffic read-heavy APIs), REST retains a major advantage in its native HTTP caching for APIs.
GraphQL Federation: Scaling Across Teams
One of the most significant recent developments in the GraphQL ecosystem is Federation - a model for composing multiple GraphQL schemas, each owned by a separate team, into a single unified API that clients interact with as though it were a monolith.
Apollo Federation, released in 2019, tackles one of GraphQL's toughest scaling problems. It helps large organizations with many independent teams (each responsible for different data domains) collaborate on a single coherent API.
In a federated architecture, each team defines and deploys its own subgraph. This is a self-contained GraphQL schema covering their domain (users, products, orders, reviews). A central gateway or router composes these subgraphs into a single unified schema.
When a client query covers multiple domains, the router automatically breaks it down, sends it to the right subgraphs and then brings the responses together into one coherent answer.
Over 400 internal microservices were coordinated into a single developer-facing API by Netflix's API team through a federated GraphQL approach. Instead of a central platform team having to integrate every microservice into one monolithic schema, each service team owns its own subgraph.
Organizational scalability results as a result. Teams can develop their subgraphs independently and without having to coordinate through a central API team.
GraphQL Subscriptions and Real-Time Architecture
GraphQL subscriptions provide the real-time component of the specification. Clients receive data pushed from the server when specific events occur. The client subscribes to a defined event type and the server streams updates over a persistent connection, typically WebSocket.
A subscription for live comment feeds:
subscription {
commentAdded(postId: "789") {
id
text
author {
name
avatarUrl
}
}
}The server maintains the connection and pushes data whenever a new comment is added to that post. The client receives the data in the same shape as a regular GraphQL response.
Managing subscriptions brings major infrastructure complexity. Stateful server connections are needed for them (unlike REST or stateless GraphQL query/mutations). Load balancers have to treat WebSocket sessions the same way each time and horizontal scaling calls for a pub/sub layer such as Redis to route events to the right server instance.
For many real-time use cases, simpler alternatives may achieve the same result with less architectural complexity. These include Server-Sent Events for one-way streaming, polling or webhook callbacks.
GraphQL subscriptions are most appropriate when the WebSocket connection is already required for other reasons or when the consistent GraphQL developer experience across queries, mutations and subscriptions is worth the infrastructure cost.
The GraphQL Ecosystem in 2024 and Beyond
The GraphQL ecosystem has matured considerably from its 2015 open-source release. The GraphQL Foundation, hosted by the Linux Foundation since 2018, now stewards the specification, with member organizations including Meta, Google, Amazon, IBM, Microsoft, and Shopify contributing to the governance process.
This institutional backing has ensured that GraphQL's development is not controlled by a single company - a concern that arose early given Facebook's origin role.
Key ecosystem developments shaping the landscape:
GraphQL over HTTP: A formal specification (finalized 2023) standardizing how GraphQL should behave over HTTP, addressing ambiguities in the original specification that had led to inconsistent implementations.
Incremental delivery (@defer and @stream). These are experimental directives that let big query results be sent progressively. This gives a major performance boost for queries that bring together fast-returning data and slow-returning data.
Rather than waiting for the slowest resolver before sending anything, the server can stream partial results as they become available.
Schema Registry patterns. With the adoption of GraphQL scaling up, organizations have put in place schema registry services (much like container registries). These services keep track of schema versions, check proposed changes for backward compatibility and offer a single source of truth for the composed API surface.
Teams starting to adopt GraphQL in 2024 can expect the ecosystem to be mature enough that the risk from tooling is low.
Instead of asking "is GraphQL production-ready?", the main question is now "does GraphQL fit my specific use case better than REST?" Most teams that have heterogeneous clients and complex data relationships still get a yes answer.
Sources and Further Reading
- Apollo Federation documentation.
- Byron, L. (2015). GraphQL: A data query language. Engineering at Meta.
- GitHub GraphQL API documentation.
- GraphQL Foundation. View source
- GraphQL Specification. GraphQL Foundation. View source
- GraphQL over HTTP specification. View source
- Introduction to GraphQL. graphql.org. View source
- Shopify GraphQL Admin API reference.








