Book Image

Practical gRPC

By : Joshua B. Humphries, David Konsumer, David Muto, Robert Ross, Carles Sistare
Book Image

Practical gRPC

By: Joshua B. Humphries, David Konsumer, David Muto, Robert Ross, Carles Sistare

Overview of this book

While building systems that contain several components, you need a framework that is fast and has minimal network overhead. gRPC is one such open-source tool that is quickly becoming popular and gaining popularity with programmers. Practical gRPC introduces you to gRPC and explains how it compares and contrasts with similar technologies. You’ll be introduced to key technologies such as Protocol Buffers, and work your way up from basic gRPC usage, all the way through to its more advanced capabilities. You’ll learn the best practices for defining and evolving your gRPC APIs, and discover how different tools can be leveraged to get the most out of gRPC and even extend it. By the end of this book, you'll have all the information you need to get started building systems with gRPC.
Table of Contents (13 chapters)
11
11. Extending gRPC services

Bidirectional streaming

The final streaming method is bidirectional (bidi) streaming. This involves having the client and the server streaming messages to each other. Messages are guaranteed to be received in the order they were sent (on both ends), but there is no need to wait for the other side to start or finish sending before you start sending messages.

Let’s take a look at an example application that uses bidi streaming. Here we’ll create a word counting application. The basic idea is to implement something like a distributed map/reduce job, where files are mapped by the tokenizer service, and the driver (client) handles the reduce step (i.e. merging the results).

Clients will stream files to the server, which for each message, will generate a map of word counts in the file. The client will then merge the results as they come in to form a final unified word map (occurrences in all of the files).

Creating the protobuf file

As always, let’s start by defining...