Sobes.tech
Junior — Middle

Can you explain the principle of operation of gRPC and its main features?

sobes.tech AI

Answer from AI

gRPC is a modern RPC framework developed by Google. It operates over HTTP/2, providing efficient bidirectional communication, stream multiplexing, and header compression.

Main features of gRPC:

  • Uses Protocol Buffers (protobuf) for describing services and data serialization — a compact and fast format.
  • Supports several call types: unary (single request — single response), server streaming, client streaming, and bidirectional streaming.
  • Provides a strictly typed contract between client and server.
  • Facilitates easy code generation in various programming languages.

Example of a simple gRPC service in Go:

// Service definition in protobuf
syntax = "proto3";

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

After code generation, you can implement server and client using the generated interfaces.