Introduction to gRPC
gRPC:
gRPC is an open source remote procedure call framework that can run any environment. It enables client and server applications to communicate transparently each other with help of HTTP/2. Mostly gRPC supports micro service oriented architecture.
gRPC supports Java, C++, Dart, Python, C#, Ruby, PHP, Go, NodeJs and JavaScript etc…
for example, you can easily create a gRPC server in c++ with clients in Go, Python, or Ruby.
Features of gRPC:
1. It supports the HTTP/2.
2. gRPC messages are serialized using Protobuf by default in a binary format.
3. gRPC supports client, Server & Bi directional streaming.
4. Protobuf compiler will generate code automatically.
5. It supports authentication, load balancing, logging and monitoring, timeouts& cancellation etc…
gRPC Streaming Types:
1. Unary RPCs: It’s normal function call. the client sends a single request to the server and gets a single response back.
2. Server streaming RPCs: The client sends a request to the server and gets response stream in the form of sequence of messages. For examples: Suppose if you watch videos in Netflix, YouTube etc. server can send the video content in the form of chunks.
3. Client streaming RPCs: The client writes a sequence of messages and sends them to the server, for example: If you upload a files to server.
4. Bidirectional streaming RPCs: Both client & server send a sequence of messages using a read-write stream. The two streams operate independently & they can read & write based on whatever order they like.
The gRPC works with protobufs concept. The Protocol buffers are a flexible, efficient for serializing structured data. The latest version of protobufs is proto3 version. The protobufs file extension is .proto type . It is Contract file which is used to communicate the client & server.
For example : .Proto file Template
Here Syntax is version of protobufs. if you don't do this the protocol buffer compiler will assume you are using proto2.
Package: which helps to prevent naming conflicts between different projects.
RPC: we can define an RPC service interface method. The protocol buffer compiler will generate service interface code.
Message: What type request data you send/receive. (if you compare similar to C# Models class object property names while sending/ receiving data.)
gRPC recommended scenarios:
1. gRPC is designed for low latency and high throughput communication. So we can use as a Microservices.
2. IOT devices
3. Point to point real time communication because it’s support bidirectional streaming etc…
4. Cloud services
Pros:
1. Inbuilt HTTP/2 protocol support.
2. It’s support bidirectional streaming with high performance.
3. The protocol buffer transfers the data in binary format.
4. It supports multi-platform.
Cons:
1. It will not support Browser.
2. It is strictly contract-first.
3. Debugging of gRPC response payloads is very difficult compared to Restful services.
For more details please visit below link:
For more detailed way to setup gRPC in .net core 3. please visit below link:
How to consume .Net core gRPC service into Python client using gRPC
Note:
I'm sharing this as per my knowledge. Anywhere, I did wrong. please let me know. I want to update myself.
Nice article