A person pouring milk into cups on top of a table.

GraphQL vs. gRPC vs. REST: Comparing Data Exchange Methods for APIs

APIs are the building blocks of the distributed systems that run our world, and they constantly move data from point to point. Different API technologies provide solutions to different pain points in API data exchange. 

Three Technologies, Three Solutions

Choosing the right technology for a project can feel daunting, but it doesn’t need to be. Each of these three technologies, REST, GraphQL, and gRPC, solves some problems better than others. Which is the best fit for you? Keeping your problem space in mind will help you choose the technology that best fits your needs.

REST

REST is the oldest and most well-known API technology. REST APIs organize data as resources that are accessed via URLs. Data is usually exchanged in JSON payloads whose formats are determined by the application that serves the data. 

REST solves a few specific problems. First, the barriers to adopting REST are low. It’s widely used and well-understood. JSON payloads are human-readable and easy to inspect. Finally, REST can provide caching via its use of URLs as unique identifiers for resources, which can improve performance.

When is REST a good fit? It’s particularly good when you need to develop quickly, or you need to bring new workers onto an ongoing project. Because the JSON payload formats are server-defined and cacheable, it works best when you don’t require flexibility in the return types of your data.

GraphQL

GraphQL allows users to HTTP request data via structured queries. The query format uses an object-like notation to specify the form and content of the data required. Requests that write data are also supported. GraphQL leverages relationships within the server-side data—the graph in GraphQL is a nod to this.

GraphQL is a good fit when you need powerful, efficient querying. Diverse data requirements can be satisfied via a single HTTP request, rather than requesting from each data source individually.

GraphQL is a good solution when different users require complex or varied views of the data. GraphQL’s object notation is fairly intuitive, but does require intentional adoption.

gRPC

gRPC uses Remote Procedure Calls to exchange data. That means that a gRPC API allows client-side code to perform remote operations on a server, such as data retrieval. What distinguishes gRPC from other RPC implementations is that API operations are first declared in a language-agnostic form, and then client code (called a stub) is automatically generated in the target language. Code stubs are used to call operations that transmit data to and from the server in a memory-efficient, language-agnostic data format called a Protocol Buffer or protobuf.

gRPC offers a few valuable solutions. First, the API’s interface is a strong contract between client and server code due to the auto-generation of code stubs. This lends stability to gRPC APIs. gRPCs also offer excellent performance via the protobuf data format. These two solutions are usually only possible within a single-language system.

gRPC is a good fit when efficiency and performance are key considerations, as in mobile devices, and when wide organizational adoption is possible.

***

Each of these API data exchange paradigms provide solutions to slightly different challenges. The one that fits you best is that one that offers solutions to the problems that you want to solve.