Go gRPC vs REST

Mayank Bhandari
4 min readDec 23, 2021

--

Understanding the significance of gRPC, and how it differs from REST API.

Understanding what APIs are, what are they used for and what they do are pre-requisites for this article. Please go through APIs before continuing this article. You can read more about APIs by following this link.

Now as you know what APIs are, the question comes what is gRPC and REST, and how is it related to API. Well, these 2 are the most popular architectural styles developers follow while creating APIs. As we already know that in a microservice architecture, APIs help to establish a connection between several small services. And so it becomes important to understand which architectural design one must follow while creating API for his/her services.

REST API definition - A REST API is an application programming interface (API or web API) that conforms to the constraints of REST architectural style and allows for interaction with RESTful web services.

gRPC definition - gRPC is a modern open-source high-performance Remote Procedure Call (RPC) framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking, and authentication.

REST

When a client/user makes a request via REST API, the response is returned in a structural representation of data in any one of several formats via HTTP. Most of the time it's JSON because it's machine and human-friendly (in terms of readability). So it's a client-server architecture, where the requests are managed through HTTP. Also, requests do not contain any client/user information, and hence requests are isolated from one another (even if made by the same client). Once REST APIs are publicly exposed, microservices can be made available for clients, which can access resources using HTTP methods like GET, PUT, DELETE, POST.

gRPC

gRPC (google Remote Procedure Call) concept looks way more simple as compared to REST. While using REST, the client communicates with the server by specifying what operation to perform like GET, POST, etc. gRPC on other hand provides an ease to the client, as the client can directly call a function on the server. The catch here is that they both share a common file known as protobuf file. It is because of this shared file, which even allows servers and clients written in different languages to communicate with one another. Protobuf defines all services and messages that are available.

REST vs gRPC

Points of difference between REST and gRPC are listed below.

HTTP 1.1 vs HTTP 2

REST APIs follow a request-response model built on HTTP 1.1 (although they can be built on HTTP 2 as well). Now the problem comes into picture when multiple requests are received from multiple clients, and because the model handles one request at a time, which eventually slows down the system. gRPC on the other hand is built on HTTP 2 and follows the client-response model. It constantly streams information, and hence simultaneously processes multiple requests from multiple clients. Also, the simple request-response (unary interaction) is also feasible in this model. gRPC allows the following interactions:-

  1. Unary streaming
  2. Server-side streaming
  3. Client-side streaming
  4. Bi-directional streaming

Code Generation

gRPC has a protoc compiler, which provides an in-built code generation feature. Microservice systems usually allow services written in different languages to communicate with each other. This protoc compiler is compatible with a wide variety of languages. REST API on the other hand does not provide an in-built code generation feature, but one can make use of third-party applications like Postman to achieve the same.

Browser Support

REST is supported by all browsers (as they are just simple request-response cycles). gRPC on other hand is very limited when comes to browser support, as it requires gRPC web and proxy layer to communicate between HTTP 1.1 and HTTP 2. Hence gRPC finds major application among developers building systems, which serves internal purposes within an organization. Example:- Google developers develop systems that are internally used by different teams working on different functionality of a product.

Conclusion

REST API is the most popular architectural design used to create APIs because they follow HTTP protocol standardization, and are hence universally acceptable. All browsers fully support them and are backed by third-party tools like Postman. But the point to note here is that they only support unary streaming. gRPC, on the other hand, has lower browser support. But are widely used by the software industry, as internal systems developed within organizations are mostly based on gRPC. The reason is simply that they provide different interactions (unary, server-side, client-side, and bi-directional), and allow clients to directly call functions present on servers. Also, the in-built code generation feature helps rapidly develop services. One more thing worth noting here is that the systems build on gRPC are extremely powerful and fast compared to those of REST.

Feel free to comment below your feedback. Thanks :)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Mayank Bhandari
Mayank Bhandari

Written by Mayank Bhandari

Software Engineer who loves working with data, to enhance user experience.

No responses yet

Write a response