Skip to content

01 Why streaming

Unary RPCs return one reply per request. That works well for lookups and commands, but some responses are naturally sequential: a progress feed, a search result set, or a series of greetings. Server-streaming lets the server push many messages over a single call without the client polling or opening new connections.

Unary vs server-streaming

UnaryServer-streaming
Requests11
Replies10 … N, then stream ends
Use caseSingle lookup, createFeeds, progress, bulk results

In a unary call the server calls callback(null, response) once and the call is done. In server-streaming the server calls call.write(chunk) as many times as needed and then call.end() to signal completion.

When to use it

Use server-streaming when:

  • The reply is large and you want to start processing before it all arrives.
  • The number of results is unknown or unbounded.
  • You want to push updates to the client without the client re-requesting.

The next page adds the SayHellos streaming method to greeter.proto.

Next: 02 The streaming proto