Home Knowledge Base gRPC

gRPC is the high-performance Remote Procedure Call framework developed by Google that uses HTTP/2 for transport and Protocol Buffers for serialization — enabling efficient bidirectional streaming, strict type-safe contracts, and 5-10x faster inter-service communication than REST/JSON, making it the standard for internal microservice communication and ML model serving APIs.

What Is gRPC?

Why gRPC Matters for AI/ML

Core gRPC Concepts

Service Definition (.proto): syntax = "proto3";

service RAGPipeline { // Unary: single request, single response rpc Retrieve(RetrieveRequest) returns (RetrieveResponse);

// Server streaming: single request, stream of responses (LLM token streaming) rpc Generate(GenerateRequest) returns (stream GenerateChunk);

// Bidirectional: stream of requests, stream of responses rpc EmbedBatch(stream EmbedRequest) returns (stream EmbedResponse); }

Python gRPC Server: import grpc from concurrent import futures import rag_pb2_grpc

class RAGServicer(rag_pb2_grpc.RAGPipelineServicer): def Retrieve(self, request, context): docs = vector_db.search(request.query, top_k=request.top_k) return RetrieveResponse(documents=docs)

def Generate(self, request, context): for token in llm.stream(request.prompt): yield GenerateChunk(token=token) # Streams tokens as generated

server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) rag_pb2_grpc.add_RAGPipelineServicer_to_server(RAGServicer(), server) server.add_insecure_port("[::]:50051") server.start()

Python gRPC Client: import grpc import rag_pb2, rag_pb2_grpc

with grpc.insecure_channel("rag-service:50051") as channel: stub = rag_pb2_grpc.RAGPipelineStub(channel)

# Stream tokens from LLM for chunk in stub.Generate(GenerateRequest(prompt="Explain gRPC")): print(chunk.token, end="", flush=True)

gRPC vs REST

AspectgRPCREST/JSON
ProtocolHTTP/2HTTP/1.1 or 2
FormatBinary (Protobuf)Text (JSON)
StreamingNative (4 modes)SSE/WebSocket needed
Type safetyEnforced by schemaOptional (OpenAPI)
Performance5-10x fasterBaseline
Browser supportLimited (gRPC-Web)Universal
Best forInternal services, ML servingPublic APIs

gRPC is the RPC framework that makes high-performance distributed ML systems practical — by combining HTTP/2 multiplexing with Protocol Buffers encoding and auto-generated type-safe clients, gRPC eliminates the serialization overhead and type mismatches that plague JSON-based microservice communication, enabling the kind of efficient inter-service data transfer that large-scale ML inference pipelines require.

grpcrpcstreaming

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.