Rest VS GraphQL VS gRPC: the communication clash

What channel for communication should you use in 2023?

Matteo Possamai
CodeX
4 min readFeb 12, 2023

--

Photo by Rolf Erik Lekang on Unsplash

Representational State Transfer (REST) is a popular architectural style that has been widely adopted for building web-based applications.

GraphQL, on the other hand, is a relatively new technology that has been gaining popularity due to its ability to handle complex data requirements and improve performance.

Finally, gRPC is a high-performance, open-source framework for building remote procedure call (RPC) APIs.

Each of these technologies has its own strengths and weaknesses, and the choice of which one to use will depend on the specific needs of the user.

In this article, we’ll compare REST, GraphQL, and gRPC, highlighting their key strengths and drawbacks and exploring when each one might be the best choice.

REST:

REST is an architectural style for building web-based applications that relies on a stateless, client-server model. This means that clients (e.g. web browsers) send requests to servers (e.g. web servers) and receive responses.

REST is popular because it is simple and well-understood, making it easy for developers to get started with building web-based applications.

One of the key strengths of REST is its simplicity. REST APIs are easy to understand and implement, and there are a large number of tools and libraries available for working with REST APIs.

Additionally, because REST is a well-established technology, there is a wealth of knowledge and resources available to help developers get the most out of it.

However, one of the biggest drawbacks of REST is that it can be difficult to handle complex data requirements.

REST APIs typically use HTTP verbs (e.g. GET, POST, PUT, DELETE) to perform actions, but these verbs are limited in their expressiveness.

This means that it can be difficult to handle more complex data requirements, such as handling multiple resources in a single request or handling real-time updates.

GraphQL:

GraphQL is a query language and runtime for APIs that was developed by Facebook.

It allows clients to specify exactly what data they need, rather than having to request more data than they need.

This means that GraphQL APIs can be more efficient than REST APIs because they allow the client to only receive the data that it actually needs.

One of the key strengths of GraphQL is its ability to handle complex data requirements. GraphQL allows clients to request exactly the data that they need, and it provides a flexible and expressive way to query data.

This makes it possible to handle more complex data requirements, such as handling multiple resources in a single request or handling real-time updates.

Another strength of GraphQL is its ability to improve performance.

Because clients can request only the data that they need, GraphQL APIs can reduce the amount of data that is transferred over the network, improving the overall performance of the application.

However, one of the biggest drawbacks of GraphQL is that it is a relatively new technology, and there is a learning curve associated with getting started with it.

Additionally, because GraphQL is still evolving, there may be some compatibility issues with different implementations of the technology.

gRPC:

gRPC is a high-performance, open-source framework for building remote procedure call (RPC) APIs.

It allows clients to make remote calls to servers, and it is designed to be fast and efficient. gRPC is built on top of Protocol Buffers, a language-agnostic binary serialization format, and it uses HTTP/2 as its transport protocol.

It is the fastest way to communicate, so if performance is needed, it is the best choice.

The pitfalls of this communication system are not neglectable. It has no browser support yes, it is quite difficult to start using it, due to the learning curve, and to use it you need to write quite a few of boilerplate codes in the form of proto files.

Conclusions

In the end, all these channels have their own strength and there are different places where they perform better.

If you want to share data and you don’t have a specified schema to follow, or you want to have as simple and compatible architecture as possible, go for REST.

If you have well-defined schemas, and no need for a complicated backend, but just a language that is able to retrieve data from a database pretty efficiently, GraphQL is what you are in search of.

If you need mere performance across your communications and maybe these communications are between services in the backend of your project, gRPC is definitely the best way to build them.

Hope that this guide clarifies eventual doubts and gave good insights. Thank you for your time

--

--

Matteo Possamai
CodeX

Computer science student, technology enthusiast, interested in backend services, software development and Open Source.