What Is gRPC? [Quick Guide]

Miguel Ratia
Strands Tech Corner
4 min readFeb 15, 2021
Created by vectorjuice

With this guide you will quickly know what gRPC is.

Below you will find the main aspects of this framework. With them you will get a clear idea about it. Let’s get started!

What is gRPC?

Google Remote Procedure Call (gRPC) is an open source framework for high performance remote procedure calls that works in a wide variety of languages.

A bit of history

gRPC was developed by Google, under the name Stubby, to connect thousands of microservices built with disparate technologies. Initially, it was not standardized to be used as a generic framework as it was closely tied to Google’s internal infrastructure.

In 2015 Google liberalized it as open source and standardized it for community use, under the name gRPC.

During the first year of its launch, it was adopted by large companies such as CoreOs, Netflix, Docker or Cisco among others.

Due to its popularity, in 2017 gRPC became part of the Cloud Native Computing Foundation.

And now let’s get into details…

What are Protocol Buffers?

Protocol Buffers (Protobuf) is the mechanism that gRPC uses to serialize structured data. Instead of using a textual format like JSON or XML, it uses a binary protocol which makes it more efficient.

The mechanism consists of an interface definition language and a code generator.

Through its interface definition language, Protocol Buffers allows you to easily define services with remotely called methods, their parameters, return types, etc. That definition is stored in text files with the extension .proto.

Based on the definition of the services in the .proto files, the Protoc compiler generates server and client code in different languages. The generated code also fully implements the communication between client and server. You can check the complete list of languages on the gRPC official website.

gRPC communication patterns

Common communication between a client and the server is done using the traditional pattern of sending a request and receiving a response. gRPC uses HTTP/2, that allows it to have three more communication patterns, in addition to the traditional one.

gRPC unary

This is the equivalent of the traditional pattern in which the client calls a remote function using a single request and the server returns a single response.

gRPC server streaming

In this pattern the client calls a remote function using a single request and the server returns multiple responses.

gRPC client streaming

This pattern is the reverse of the previous one. The client calls a remote function using multiple requests and the server returns a single response.

gRPC bidirectional streaming

The bidirectional pattern is the most complex. Through this, the client calls a function using multiple requests and the server returns multiple responses.

Workflow to create a gRPC application

The typical flow of creating a gRPC application consists of the following steps:

  1. Define the service using Protocol Buffers in a .proto file, detailing the remote methods it offers.
  2. Generate the gRPC code for the client and server from the .proto file using the Protocol Buffers Protoc compiler.
  3. Implement the logic of the methods defined in the service on the server.
  4. Implement the processing of calls and responses to server methods on the client.

gRPC vs REST

REST is the most popular architecture in recent times to build server applications that provide synchronous request-response communication. However, it does not meet all the requirements that some modern microservices demand.

While REST is a perfect solution for simple APIs, gRPC has become the ideal choice for more complex interfaces and services, because it offers streaming communication, higher speed and better performance.

Today gRPC has limitations of use mainly in web applications since the HTTP/2 protocol is not fully extended among browsers. For its part, the REST implementation is fully adapted to any type of application.

gRPC is not the best option to expose an application for external consumption since consumers are currently more familiar with REST and it also allows more flexibility of use.

Although at first glance gRPC could seem the clear winner, since it is a relatively new technology that has some disadvantages compared to REST.

Conclusion: Why use gRPC?

Many famous companies are embracing this technology and it is even rumored to be the future of microservices and APIs that will be used by mobile applications.

The key to increasing use of gRPC is the benefits it provides:

  • It can be used in a wide variety of programming languages.
  • It is API-oriented and that gives you more freedom in interface design.
  • The rules of its syntax facilitate the maintenance of the interfaces.
  • It offers very efficient communication between processes thanks to the use of the HTTP/2 protocol.
  • Allows you to make streaming calls.
  • It incorporates security mechanisms through SSL.

--

--