#
What gRPC and Protocol buffers are ?
Protocol Buffers
(a.k.a., protobuf) are Google's language-neutral, platform-neutral, extensible mechanism
for serializing structured data.
The format is suitable for both ephemeral network traffic and long-term data storage.
Info
Protocol buffers are the most commonly-used data format at Google. They are used extensively in inter-server communications as well as for archival storage of data on disk.
Data structures (called messages) and services are described in a proto definition file (.proto) and
compiled with protoc
. This compilation generates code that can be invoked by a sender or recipient of these data structures.
In this picture you can see how protoc compiler is working in Protocol Buffers world:
Protocol buffers are a combination of the definition language (created in .proto files), the code that the proto compiler generates to interface with data, language-specific runtime libraries, and the serialization format for data that is written to a file (or sent across a network connection).
The following shows an example message:
message Person {
string name = 1;
int32 id = 2;
optional string email = 3;
}
Info
int32 : Inefficient for encoding negative numbers. sint32 : (Signed int value) : Efficiently encode negative numbers.
Advantage of using Protocol Buffers:
- Compact data storage
- Fast parsing
- Availability in many programming languages
- Optimized functionality through automatically-generated classes
When it is not used:
- Data structures are bigger than a few megabytes in size (Protocol buffers tend to assume that entire messages can be loaded into memory at once)
- Protocol buffers are not well-supported in non-object-oriented languages popular in scientific computing
- Protocol buffers are not a formal standard of any organization. This makes them unsuitable for use in some environments
- You cannot fully interpret the message without access to its corresponding .proto file.
gRPC
is a modern open source high performance Remote Procedure Call (RPC) framework that can run in any environment.
Here are the supported languages for gRPC.
gRPC use Protocol Buffers for message serialization.
gRPC is based around the idea of defining a service
, specifying the methods that can be called remotely with
their parameters and return types.
You define gRPC services in ordinary proto files, with RPC method parameters and return types specified as protocol buffer messages:
// The greeter service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
More information on this you can get from here.