Advertisement
Advanced ASP.NET Core, gRPC Services

How do the four gRPC method types (unary, server streaming, client streaming, bidirectional streaming) differ, and when would you use each?

Short answer

Unary (single request, single response) is the default and covers most simple RPC calls, analogous to a typical REST call. Server streaming (single request, stream of responses) suits scenarios like a live feed of updates from one initial request.

Save ASP.NET Core mock interview
Advertisement
AModel answer
Unary (single request, single response) is the default and covers most simple RPC calls, analogous to a typical REST call. Server streaming (single request, stream of responses) suits scenarios like a live feed of updates from one initial request. Client streaming (stream of requests, single response) suits scenarios like uploading a large dataset in chunks before getting one final result. Bidirectional streaming (both streams simultaneously, independent of each other) suits real-time, two-way scenarios like a chat application or live collaborative editing.
service DataService {
  rpc GetItem (ItemRequest) returns (Item);  // unary
  rpc StreamUpdates (SubscribeRequest) returns (stream Update);  // server streaming
  rpc UploadItems (stream Item) returns (UploadSummary);  // client streaming
  rpc Chat (stream ChatMessage) returns (stream ChatMessage);  // bidirectional
}
Real-world example
A stock ticker service uses server streaming to push continuous price updates to a subscribed client from a single subscription request, while a log ingestion service uses client streaming to let an agent send a continuous stream of log entries before receiving one final batch-acknowledgment response.
Likely follow-ups
  • How does cancellation work differently across these four streaming patterns?
  • What are the connection/resource lifetime implications of long-lived streaming calls?
Related topics