liveBook · Manning

Bidirectional streaming

As explained in gRPC Microservices in Go

Bidirectional streaming is an RPC communication mode in which client and server exchange independent streams of messages.

Bidirectional streaming lets a gRPC client and server exchange message streams over one opened connection. Both sides can continue sending messages, supporting asynchronous communication instead of repeated request-response calls. section 1.1.5 section 2.5.2

Choose bidirectional streaming when the interaction requires ongoing traffic in both directions:

  • Use it to send multiple client requests continuously while the server returns result objects as a stream. section 2.5.2
  • Prefer it over repeated pagination or unary calls when an open connection can deliver data progressively and reduce communication delay. section 1.1.5 section 1.2
  • Track each asynchronous operation with a unique identifier so failures can be associated with the correct request. section 2.5.2
  • Account for browser limitations: REST remains broadly supported, while browser-facing gRPC deployments may require a gRPC Web proxy. section 1.2

Streaming payment creation

A payment client streams payment requests to a service while the service streams back operation results. Because responses may complete asynchronously, each request should carry or receive an identifier that distinguishes failures and statuses. section 2.5.2

service Payment {
    Create(stream CreatePaymentRequest) 
    returns (stream CreatePaymentResponse){}
}

A protobuf service declaration expresses bidirectional streaming by marking both the request and response as streams. section 2.5.2

How gRPC Microservices in Go covers it

How deep it goes
Defines the communication mode and shows its protobuf signature, but defers detailed implementation to a later treatment.
Examples
Uses payment requests, streamed payment responses, pagination alternatives, and a protobuf service declaration.
What you can do after
Apply it via gRPC by defining streaming requests and responses in a protobuf service contract.
How it connects
Connects client streaming, server streaming, RPC, protocol buffers, HTTP/2, REST, and gRPC Web.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of gRPC Microservices in Go. The section links point to the parts of the book it draws on.