Middle+
What is gRPC and how does it differ from regular HTTP?
sobes.tech AI
Answer from AI
gRPC is a modern framework for remote procedure calls (RPC), developed by Google. It uses HTTP/2 as the transport protocol and Protocol Buffers (protobuf) for data serialization.
Main differences of gRPC from regular HTTP:
- Protocol: gRPC operates over HTTP/2, which provides multiplexing requests, header compression, and a binary transfer protocol, unlike the text-based HTTP/1.1.
- Data format: gRPC uses protobuf — a compact, binary format, whereas regular HTTP often uses JSON or XML.
- Call types: gRPC supports not only request-response but also streaming data in both directions (client-server).
- Performance: thanks to the binary protocol and HTTP/2, gRPC is usually faster and more efficient than REST over HTTP/1.1.
Example of defining a service in protobuf for gRPC:
syntax = "proto3";
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply);
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
In C#, code for client and server is generated based on this description for convenient method calls.