0Pricing
gRPC & High Performance APIs · レッスン

ストリーミングRPC:サーバー、クライアント、双方向

単項呼び出しを超えて、1回の呼び出しで一連のメッセージを送信するgRPCの3種類のストリーミングモードを学びます。

「ストリーミングRPC:サーバー、クライアント、双方向」はCoddyKit上の無料gRPC & High Performance APIsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはgRPC & High Performance APIs学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 gRPC & High Performance APIsコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Beyond Unary

A unary RPC is one request, one response. But many problems need a sequence of messages — feeds, uploads, chat.

gRPC offers three streaming modes built on HTTP/2 streams.

The Four Method Shapes

In a .proto service you can declare:

  • Unary: one in, one out.
  • Server streaming: one in, many out.
  • Client streaming: many in, one out.
  • Bidirectional: many in, many out.

Declaring Streams in Proto

The stream keyword marks a parameter as a stream.

service Feed {
  rpc Watch (WatchRequest) returns (stream Event);
  rpc Upload (stream Chunk) returns (UploadResult);
  rpc Chat (stream Message) returns (stream Message);
}

Server Streaming

The client sends one request; the server replies with many messages until it closes the stream.

Great for: live feeds, large result sets, progress updates.

// Server side (Go-style pseudocode)
func (s *server) Watch(req *WatchRequest, stream Feed_WatchServer) error {
  for _, e := range events {
    stream.Send(e)
  }
  return nil
}

Client Streaming

The client sends many messages, then the server returns a single response.

Great for: file uploads, batched ingestion, aggregations.

// Server reads the whole client stream, then replies once
func (s *server) Upload(stream Feed_UploadServer) error {
  for {
    chunk, err := stream.Recv()
    if err == io.EOF {
      return stream.SendAndClose(&UploadResult{})
    }
  }
}

Bidirectional Streaming

Both sides send streams independently over the same call. Messages can interleave freely.

Great for: chat, real-time collaboration, interactive protocols.

Why It's Efficient

All four shapes ride a single HTTP/2 stream — no new connection per message.

Multiplexing means many streaming calls share one connection without head-of-line blocking.

Flow Control

HTTP/2 provides built-in flow control, so a slow reader naturally backpressures a fast writer.

This prevents a streaming server from overwhelming a client that can't keep up.

Ending a Stream

Streams close explicitly:

  • Server streaming ends when the server returns.
  • Client streaming ends when the client signals end-of-stream and the server replies.
  • Bidirectional ends when both halves complete or an error/cancel occurs.

Errors & Cancellation

Either side can cancel or fail mid-stream. The peer receives a status code and should clean up.

Always handle EOF and error returns from Recv() / Send() to avoid leaks.

Choosing a Mode

Pick by data shape:

  • One-shot request/response: unary.
  • Push many results: server streaming.
  • Send many, get a summary: client streaming.
  • Continuous two-way: bidirectional.

Quick Check

Test your understanding of streaming RPCs.

Recap

You learned gRPC's streaming modes.

  • Unary, server streaming, client streaming, and bidirectional.
  • Mark streams with the stream keyword in proto.
  • All ride a single multiplexed HTTP/2 stream with built-in flow control.
  • Choose the mode that matches your data's shape.

よくある質問

「ストリーミングRPC:サーバー、クライアント、双方向」レッスンは無料ですか?

はい。「ストリーミングRPC:サーバー、クライアント、双方向」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、gRPC & High Performance APIsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 gRPC & High Performance APIsコースには全4レッスンが含まれています。

「ストリーミングRPC:サーバー、クライアント、双方向」で何を学びますか?

単項呼び出しを超えて、1回の呼び出しで一連のメッセージを送信するgRPCの3種類のストリーミングモードを学びます。 ブラウザで直接実行するハンズオンコードでgRPC & High Performance APIsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

gRPC & High Performance APIsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのgRPC & High Performance APIsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「ストリーミングRPC:サーバー、クライアント、双方向」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このgRPC & High Performance APIsレッスンでコードを書いて実行できますか?

はい。すべてのgRPC & High Performance APIsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Protobufスキーマの定義
  2. gRPCコードの生成
  3. シンプルなUnary gRPCサービス
  4. ストリーミングRPC:サーバー、クライアント、双方向
← gRPC & High Performance APIsに戻る