Photo by Pavan Trikutam on Unsplash

What is gRPC and why should you use it?

Sriram Kumar Mannava
2 min readOct 17, 2023

--

RPC stands for Remote Procedure Call (RPC).

It is a protocol used in distributed systems where clients call procedures (or methods) inside the server as if they were methods in another class.

The advantage here is that the client doesn’t know the underlying details about how the call is being made to the remote procedure.

gRPC system uses a contract mechanism – the client defines a contract with details about the procedure it knows and how it expects to communicate (parameters and return).

This is written in .proto files in a specific syntax and is shared between both the server and the client.

The server takes this contract and implements the Services based on this contract.

The client calls these procedures that it already defined in its contract on the server as if its yet another method call, using a channel object.

The entire interaction happens between client-server over HTTP/2 with Protobuf as the underlying data encoding mechanism.

For comparison, a REST API written over HTTP generally uses JSON as the data format.

Protobuf requires strict specification of the message types and procedure definition, and provides a common experience irrespective of the platform it is being implemented. The advantage? cross-platform communications.

You'll generally implement gRPC in the following sequence -
1. Defining a procedure contract written in a proto file
2. server digests this contract and builds a service implementation
3. client digests this contract and builds a Client proxy (component)
4. client calls any method of the server desceibed in the contract via its local proxy

gRPC is a fast and simple communication protocol over the traditional RESTful approach.

We can use this to build interactions between microservices in a microservice architecture when a microsevice needs to call another microservice.

You can find this article that I have written that explains how to build gRPC service communication in ASP.NET Core here — https://referbruv.com/blog/building-a-simple-client-server-interaction-with-grpc-in-aspnet-core/

--

--

Sriram Kumar Mannava

I make Full Stack Development Easy for You | Full Stack .NET Dev | 3× AWS Certified | Blogger