Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Graphql offer any performance increase over Rest API?

Tags:

rest

graphql

After learning about Graphql, I have understood that it has many advantages over Rest API, one of which most commonly mentioned is to do with convenience.

But does Graphql actually offer any performance increase over Rest API though?

like image 654
Daniel Izham Avatar asked Dec 19 '25 03:12

Daniel Izham


2 Answers

This is a very general question, and therefor the general answer - it depends.

It depends on your use case, if you have nested objects that require multiple calls in a 'standard' REST architecture like @RAVI_SINGH answered, than yes, graphql can decrease the number of calls requires and thus increased performance. But this really depends on your use case.

On the other hand, if you don't have such cases, and don't need the 'power to the client' capabilities graphql provides, than you do pay something in performance, when doing all the selection set calculation for example.

So like almost everything, there's good and bad in graphql, and it can improve the performance or not, depending on your model and how you implement and use it

like image 119
Nir Levy Avatar answered Dec 21 '25 19:12

Nir Levy


Yup definitely. If you just google GraphQL vs. REST you will get many answers but I will give you one example which will explain everything.

Let’s suppose you want to get some books' details with their respective reviews from your REST server which has separate endpoints -- for example, /books and /reviews

  • REST: If you are making a direct call to your REST server then first you have to make a call to get all book details and then for each book's ID you will make a call to get its review from the /reviews endpoint. This way you end up making n+1 calls.
  • GraphQL: If you are using GraphQL as an intermediate server, you will write only one query that will do everything for you. This means your GraphQL server will understand the query and in one query only it will first fetch all the book details and then it will fetch review for each book.

Using Data Loader you can optimize your GraphQL server even more.

Refer to this link to learn more.

like image 34
RAVI SINGH Avatar answered Dec 21 '25 19:12

RAVI SINGH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!