grpc-go

gRPC

Specific best practices and architectural patterns when working with gRPC.

Details

Language / Topic
goGo
Category
framework

Rules

balanced

gRPC-Go

- Define services in `.proto` files — generate Go code with `protoc-gen-go-grpc`. Use unary RPCs for request-response, streaming for large payloads or real-time data. Always return proper gRPC status codes (`codes.NotFound`, `codes.InvalidArgument`).

gRPC-Go

- Define services in `.proto` files — generate Go code with `protoc-gen-go-grpc`. Use unary RPCs for request-response, streaming for large payloads or real-time data. Always return proper gRPC status codes (`codes.NotFound`, `codes.InvalidArgument`).
- Use interceptors (unary and stream) for cross-cutting concerns: logging, auth, metrics, tracing. Implement `grpc.UnaryServerInterceptor` chains. Use `metadata` for request context (auth tokens, request IDs). Set deadlines with `context.WithTimeout` on every client call. Use `grpc-gateway` to expose gRPC services as REST APIs.