Implement gRPC streaming (server, client, bidirectional)
✓Works with OpenClaudeYou are a gRPC protocol expert. The user wants to implement server-side streaming, client-side streaming, and bidirectional streaming with gRPC using protocol buffers.
What to check first
- Run
protoc --versionto ensure protocol buffer compiler is installed - Verify your gRPC language runtime is installed:
npm list grpc(Node.js) orpip list | grep grpcio(Python) - Check that your
.protofile is in the correct directory and includessyntax = "proto3";at the top
Steps
- Define your proto messages and service with streaming RPC methods using
streamkeyword in.protofile - Compile proto files with
protoc --go_out=. --go-grpc_out=. service.proto(Go) or equivalent for your language - Implement the service interface in your server code, handling
Send()for server-streaming and receiving streams for client/bidirectional - Create a server listener with
lis, err := net.Listen("tcp", ":50051")and register your service - In client code, call streaming methods which return
grpc.ServerStreamorgrpc.ClientStreaminterface - Use
stream.Send()to write messages andstream.Recv()to read messages in a loop - Call
stream.SendAndClose()on server side when done sending in client-streaming scenarios - Handle context cancellation with
context.WithCancel()for graceful shutdown of long-lived streams
Code
// chat.proto
syntax = "proto3";
package chat;
option go_package = "github.com/example/chat";
message Message {
string sender = 1;
string text = 2;
}
service ChatService {
// Server streaming: one request, multiple responses
rpc GetMessages(Message) returns (stream Message);
// Client streaming: multiple requests, one response
rpc SendMessages(stream Message) returns (Message);
// Bidirectional streaming: multiple requests and responses
rpc Chat(stream Message) returns (stream Message);
}
// server.go
package main
import (
"context"
"fmt"
"io"
"log"
"net"
"google.golang.org/grpc"
pb "github.com/example/chat"
)
type server struct {
pb.UnimplementedChatServiceServer
}
// Server streaming: send multiple messages for one request
func (s *server) GetMessages(req *pb.Message, stream grpc.ServerStream) error {
for i := 0; i < 3; i++ {
response := &pb.Message{
Sender: "Server",
Text: fmt.Sprintf("Message %d from %s", i+1, req.Sender),
}
if err := stream.SendMsg(response); err != nil {
return err
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related gRPC Skills
Other Claude Code skills in the same category — free to download.
gRPC Setup
Set up gRPC service with protocol buffer definitions
gRPC Client
Create type-safe gRPC client with error handling
gRPC-Web
Set up gRPC-Web for browser clients
Protobuf Generator
Generate code from protobuf definitions for multiple languages
gRPC Streaming Patterns
Implement server-streaming, client-streaming, and bidirectional gRPC streams with backpressure
gRPC Interceptors
Add cross-cutting concerns (auth, logging, metrics) using gRPC interceptors
gRPC Error Handling
Map application errors to gRPC status codes correctly
Want a gRPC skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.