Course contentsShow
← Software Engineering
Lesson 802 of 1,93325. RPC and GraphQL API DesignFree lesson

gRPC Streaming: Unary, Server, Client, and Bidirectional

Understanding gRPC's four streaming patterns for different communication needs.

gRPC Streaming: Unary, Server, Client, and Bidirectional

What You'll Learn

You'll understand gRPC's four communication patterns and when to use each for different data exchange scenarios.

The Four Streaming Patterns

While traditional RPC sends one request and receives one response, gRPC supports four distinct patterns that match different communication needs:

Unary RPC

The simplest pattern: client sends one request, server returns one response. This mirrors traditional REST API calls and works well for simple queries or commands.

Think of it like asking someone a single question and getting a single answer.

Server Streaming RPC

Client sends one request, server returns a stream of responses. Perfect when the server needs to send large datasets, real-time updates, or progress notifications.

Like ordering a pizza and receiving text updates: "Order received," "Pizza in oven," "Out for delivery."

Client Streaming RPC

Client sends a stream of requests, server returns one response after processing all input. Ideal for uploading files in chunks, sending sensor data batches, or aggregating multiple inputs.

Like taking multiple photos and waiting for the camera app to create one stitched panorama at the end.

Bidirectional Streaming RPC

Both client and server send streams of messages independently. Either side can read or write in any order. Essential for chat applications, collaborative editing, or live gaming.

Like a phone conversation where both people can speak and listen simultaneously without waiting for turns.

Choosing the Right Pattern

Match the pattern to your data flow:

  • One-shot operations: Unary
  • Large downloads or live updates: Server streaming
  • Batch uploads or aggregation: Client streaming
  • Real-time collaboration: Bidirectional

Key Takeaway: gRPC's four streaming patterns (unary, server, client, bidirectional) provide flexible communication models beyond simple request-response, enabling efficient handling of real-time data, large transfers, and interactive applications.