Why GraphQL API is the perfect data layer for your backend
Tags: graphqlbackend, baas, productionreadygraph
Published: 2021-11-29 13:59:01

---
title: Why GraphQL API is the perfect data layer for your backend
published: true
date: 2021-11-25 06:14:31 UTC
tags: GraphQLBackend,BaaS,ProductionReadyGraph
canonical_url: https://hasura.io/blog/why-graphql-api-is-the-perfect-data-layer-for-your-backend/
---

*This article was originally published on the Hasura blog. If there are formatting errors in the article below, we urge you to please go to [our blog and read it there](https://hasura.io/blog/why-graphql-api-is-the-perfect-data-layer-for-your-backend/). Thanks!* :)

![Why GraphQL API is the perfect data layer for your backend](https://hasura.io/blog/content/images/2021/11/pft_data_layer.png)

GraphQL, a query language for reading and modifying data from APIs, is growing in popularity. Data from the [State of JavaScript 2020](https://2020.stateofjs.com/en-us/technologies/datalayer/) reports that 44.3% of respondents said they had used GraphQL API in 2020, compared to 5% in 2016. Many [Fortune 500 companies use GraphQL API](https://hasura.io/case-studies/philips/) for their backends in production; top companies like [Facebook](https://engineering.fb.com/2015/09/14/core-data/graphql-a-data-query-language/) and [GitHub](https://docs.github.com/en/graphql) use the API technology to improve their product offerings and boost system performance.

With the ever-changing technology landscape, you might have doubts about adopting GraphQL API for your backend and be unsure how it can improve your current data needs. However, regardless of what language or architecture you are using, GraphQL API can help simplify data access, supercharge the product development process, improve application performance, and handle complex backend data scenarios.

### One unified endpoint for your backend

One advantage of GraphQL API is that it provides a single unified endpoint for your backend to meet both client and general API use cases. A single GraphQL API can handle all the client’s requests and forward them to the correct backend service.

As companies and their products scale, REST endpoints can become large and incredibly hard to manage. One of the main problems in REST is the [N+1 problem](https://hasura.io/learn/graphql/intro-graphql/graphql-server/#:~:text=N%2B1%20performance%20problem), where the client calls the server N+1 times to get N number of resources, mainly because a single REST resource does not provide enough information for the client to operate with.

Brennan Saeta, an infrastructure engineer at Coursera, cited [centralizing REST APIs for simple consumption](https://medium.com/coursera-engineering/evolving-the-graph-4c587a4ad9a8#:~:text=centralizing%20all%20the%20REST%20APIs%20that%20our%20organization%20was%20creating%20for%20simple%20and%20easy%20consumption) by the client as one of the reasons why GraphQL API appealed to them.

GraphQL API hides the complexity of the underlying backend system by aggregating the required data from different sources and providing a simple interface that clients can communicate with through a single resource.

### Improved application performance

GraphQL API improves application performance by reducing JSON payload size and network overhead from multiple API calls. By allowing the client to specify its data requirements, GraphQL APIs eliminate the need for unnecessary generic data being passed from the backend and minimize the number of roundtrips required to retrieve backend data.

As companies scale and iterate their products, the data required by different clients and pages changes. In REST API design, when new requirements arise, developers must decide whether to create a new endpoint and have clients make a new request for that data or add more data to an existing endpoint. The first option leads to more server roundtrips, and the second option increases payload size, both of which can hinder app performance.

With more applications being accessed over flaky mobile networks and app speed being an important metric for retaining users, minimizing server roundtrips and data transferred over the wire is paramount. Companies like [Netflix](https://netflixtechblog.com/our-learnings-from-adopting-graphql-f099de39ae5f#:~:text=In%20our%20application%2C%20pages%20that%20were%20fetching%2010MB%20of%20data%20before%20now%20receive%20about%20200KB.%20Page%20loads%20became%20much%20faster%2C%20especially%20over%20data-constrained%20mobile%20networks%2C%20and%20our%20app%20uses%20much%20less%20memory) and [Pulley](https://hasura.io/case-studies/pulley/#:~:text=Excellent%20user%20experience%20thanks%20to%20fast%20performance) have reported faster page load times and overall app performance after switching to GraphQL APIs.

With GraphQL APIs, clients receive only the data they specify from the backend server in a single trip, saving network bandwidth and resources.

### Improved system reliability

GraphQL API improves system reliability by ensuring that client queries are valid and in sync with the GraphQL schema specification before query execution. GraphQL uses a type system that describes what type of data can be queried from the backend server and in what form it exists. A strongly-typed schema offers enhanced security over REST APIs by preventing breaches like SQL injection and unintentional data leaks, resulting in a more secure and reliable application.

Type-safety ensures that any breaking changes by the backend server would be caught by clients consuming the data, resulting in less downtime. With GraphQL APIs, you can modify and deprecate API fields while still maintaining backward compatibility. It is easier to know which fields in the API are being used by what clients and which ones are not. With GraphQL, API developers can confidently make changes to the existing APIs without breaking the existing functionality.

[Swiggy](https://www.youtube.com/watch?v=0YbW3XarGqM), India's largest food delivery platform, discussed how adopting GraphQL API for their backend enabled them to make changes to their existing APIs without breaking the consumer application.

Ultimately, GraphQL ensures API consistency, reliability, and security, which results in better system performance.

### Better developer experience

Adopting GraphQL APIs improves the developer experience for both frontend and backend developers. Backend developers want to build APIs that are intuitive and easy to explore and navigate. GraphQL helps with that by reducing the time spent documenting APIs.

Through a concept known as [introspection](https://hasura.io/learn/graphql/intro-graphql/introspection/), GraphQL APIs allow clients to query the schema and discover the resources available on it. With excellent tools and libraries like the GraphiQL IDE, the interactivity for GraphQL API endpoints is much more intuitive for the developer.

API consumers want APIs that are flexible, easy to integrate, and support a variety of client use cases (Web, iOS, and Android). Because of REST's inflexibility, it is challenging to create a single endpoint that can meet all of the client’s data requirements. Often the same client has to call multiple APIs to get the data it needs from the backend. Additionally, with REST APIs, frontend developers have to rely on the backend for API specifications before building product features, leading to slower development time.

Peter Downs, director of engineering at fintech startup Pipe, mentioned how choosing GraphQL API early on [cut their development time by 90%](https://hasura.io/case-studies/pipe/#:~:text=As%20mentioned%20earlier%2C%20the%20fact%20that%20Hasura%20helps%20in%20a%20~90%25%20reduction%20in%20time%20for%20new%20feature%20development%20by%20breaking%20down%20the%20traditional%20barriers%20between%20front%2Dend%20and%20back%2Dend%20engineering.%20Also%2C%20simplified%20GraphQL%20data%20fetching%20architecture%20makes%20it%20super%20easy%20to%20add%20new%20features.). With GraphQL APIs, frontend and UI developers can quickly and easily iterate on features by simply specifying the data requirements in the GraphQL API, thereby reducing the dependence on backend developers to make changes.

### Getting started with GraphQL API

The best way to learn GraphQL is by getting your hands dirty and building applications with it. Depending on your language of choice, there are [GraphQL libraries](https://graphql.org/code/) in many different languages to help you get started.

You can start by:

- **Creating a simple project using GraphQL APIs:** We recommend this[full-stack tutorial](https://hasura.io/learn/graphql/nextjs-fullstack-serverless/introduction/) on our learning platform that walks you through building a real-time to-do app using GraphQL APIs.
- **Migrating an existing REST API to GraphQL API:** We have an array of tutorials in multiple languages ([Node.js](https://hasura.io/blog/turn-your-node-js-rest-api-to-graphql/), [Python](https://hasura.io/blog/turn-your-python-rest-api-to-graphql-using-hasura-actions/), [Ruby on Rails](https://hasura.io/blog/turn-your-ruby-on-rails-rest-api-to-graphql-using-hasura-actions/), [Go](https://hasura.io/blog/turn-your-go-rest-api-to-graphql-using-hasura-actions/), [Java](https://hasura.io/blog/turn-your-java-rest-api-to-graphql-using-hasura-actions/)) to help you get started with this.
- **Integrating a GraphQL API on the frontend** : We put together a list of courses that help you get started with [integrating GraphQL in your frontend application](https://hasura.io/learn/).

As with any new technology, adopting GraphQL APIs for your backend and building high performant GraphQL backends requires experience, which is not peculiar to GraphQL alone.

Suppose your application relies heavily on interconnected data, or you aim to develop an API to be used across several clients, or perhaps you are looking for a high-performant API solution for your backend that minimizes bandwidth usage. In that case, GraphQL API is a perfect data layer for your backend.  
[Hasura](https://hasura.io/) is an open-source GraphQL API engine that helps you instantly set up a[scalable and real-time GraphQL backend](https://hasura.io/learn/graphql/hasura/introduction/), speeding up development time and making your engineering teams super productive. [Sign up here.](https://cloud.hasura.io/signup?pg=home&plcmt=header&cta=try-hasura&tech=default)