Member-only story
gRPC Communication Patterns
One of the advantages gRPC offers over REST based services is the streaming bi-directional communication. Traditional implementations which depend on REST APIs often implement Web Sockets to enable real bi-directional streaming of data packets. I said real because it is still possible to simulate streaming behavior using REST, which of course is not performant, and makes little sense.
gRPC communication patterns are of 4 kinds — Unary, Server streaming, Client streaming, and Bi-directional streaming. Depending on the communication scenario you are trying to code in your distributed system, these patterns cover all the aspects quite effectively.
In this post, we will understand these patterns with the help of the examples and diagrams. If you are not familiar with gRPC, check out this post — Intro to gRPC and Protocol Buffers using Go — which provides a quick overview of gRPC with a step-by-step instructions on how to set up gRPC in Golang based microservices. The example discussed in that post involves a calculator server and a client that consumes the arithmetic functions exposed by the calculator server. This post extends the analogy to demonstrate gRPC communication patterns.
Access the complete code example here. The code also implements SSL based auth to secure the communication between client and server.