LogoMasst Docs

gRPC

Understanding gRPC for high-performance service communication.

What is gRPC?

gRPC is a high-performance RPC (Remote Procedure Call) framework developed by Google. It uses Protocol Buffers for serialization and HTTP/2 for transport.


gRPC vs REST

AspectgRPCREST
ProtocolHTTP/2HTTP/1.1 or HTTP/2
SerializationProtocol Buffers (binary)JSON (text)
ContractStrict (.proto files)Loose (OpenAPI optional)
StreamingBuilt-inRequires WebSocket/SSE
Browser supportLimitedNative
PerformanceFasterSlower

Protocol Buffers

Define your service and messages in .proto files:

syntax = "proto3";

service UserService {
  rpc GetUser (GetUserRequest) returns (User);
  rpc ListUsers (ListUsersRequest) returns (stream User);
}

message GetUserRequest {
  int32 id = 1;
}

message User {
  int32 id = 1;
  string name = 2;
  string email = 3;
}

Communication Patterns

Unary RPC

Client ─── Request ───► Server
Client ◄── Response ─── Server

Server Streaming

Client ─── Request ───────► Server
Client ◄── Response 1 ───── Server
Client ◄── Response 2 ───── Server
Client ◄── Response N ───── Server

Client Streaming

Client ─── Request 1 ────► Server
Client ─── Request 2 ────► Server
Client ─── Request N ────► Server
Client ◄── Response ────── Server

Bidirectional Streaming

Client ◄──► Server (both send streams)

Benefits

BenefitDescription
PerformanceBinary format, HTTP/2 multiplexing
Type safetyGenerated code from proto files
StreamingNative support for all patterns
Code generationAuto-generate client/server code
Language agnosticSupport for many languages

When to Use gRPC

Good for:

  • Microservices communication
  • Low-latency, high-throughput systems
  • Streaming data
  • Polyglot environments

Not ideal for:

  • Browser clients (limited support)
  • Simple CRUD APIs
  • When human-readable format needed

Interview Tips

  • Explain Protocol Buffers and binary serialization
  • Know the four communication patterns
  • Compare performance with REST
  • Discuss when to choose gRPC vs REST
  • Mention HTTP/2 benefits (multiplexing)