gRPC Streaming Patterns
gRPC defines 4 service patterns based on whether the request and response are single messages or streams. All patterns run over HTTP/2 streams using the same length-prefixed Protobuf framing.
HTTP/2
transport
rpc Method(Request) returns (Response)Unary RPC is the simplest pattern: the client sends one request, the server sends one response. It behaves like a synchronous function call over a persistent HTTP/2 stream. Unary RPC is the right choice for most operations – CRUD, lookups, and any request-response interaction. The server may return a gRPC status code in trailers if processing fails.
rpc Method(Request) returns (stream Response)Server streaming sends one request and receives a stream of responses. The server sends multiple messages on the same HTTP/2 stream, keeping it open until the response stream is complete. Ideal for large dataset pagination, real-time feed subscriptions, file downloads, and log tailing where the server generates results over time.
rpc Method(stream Request) returns (Response)Client streaming sends multiple request messages on a single RPC before receiving one response. The server waits for all client messages (or processes them as they arrive) and returns a single response when the client closes the stream. Used for bulk data upload, file upload in chunks, and aggregation operations where the server accumulates input before responding.
rpc Method(stream Request) returns (stream Response)Bidirectional streaming opens a full-duplex HTTP/2 stream where both client and server can send messages independently at any time. Each side sends a stream and receives a stream. The order and interleaving of messages is application-defined. Used for real-time chat, live collaboration, gaming state sync, and any scenario requiring simultaneous two-way message flow.