Link Search Menu Expand Document

gRPC Lab

Machines in a distributed system must communicate with one another. One method of doing this is using Remote Procedure Calls (RPCs), which make communication between machines look like ordinary function calls. Effectively, RPCs abstract away the underlying serialization required for raw messaging and allow for an interaction like this:

  • A client calls remoteFileSystem->Read("rutabaga").
  • The underlying RPC library serializes this function call as a request and sends it to the server.
  • The RPC library deserializes the request on the server and runs fileSys->Read("rutabaga"), which returns a response.
  • The RPC library serializes the response, sends it to the client, and deserializes it to give the client the return value for its function call.

Serialization is the process of converting structures into bytes that can be sent via communication protocols like TCP, while deserialization recovers the original structures from the serialized bytes. Serialization formats specify how serialization and deserialization should take place, and allow communicating processes to understand the bytes being received from one another. For example, JSON and YAML are two common serialization formats that often find use in configuration files.

In this lab, you will be familiarizing yourself with gRPC, an open source remote procedure call (RPC) framework that uses Google’s protocol buffer serialization mechanism. You will do so by implementing a very basic key/value (KV) store, which allows clients to put keys in a server-side hash map and read them out later by making requests to the server.

For a brief rundown of how gRPC works, please read this guide. For more specifics on how gRPC works in Rust, you can take a look at this tutorial, but we will be covering the content relevant to the upcoming MapReduce homework in this lab.

Getting started

We recommend doing this lab locally, but you can also do it from your VM. Begin by pulling the starter code:

cd ~/code/personal
git pull staff master
cd lab-grpc-rs

If you are doing the lab locally, you will need to install CMake by following the directions here. Make sure you install a relatively new version of CMake (at least 3.20.0) to ensure that you don’t run into any issues.

If Rust is not installed, install it according to the directions here.


Here are some excellent resources for learning Rust. If you are still getting up to speed with Rust, we recommend skimming over them to get a sense of what’s available, and reading relevant sections in more detail if you think they will be useful. We have posted additional resources you may find helpful on Ed.

Throughout this assignment, you will see functions labeled async. As a general rule, you must always add a .await when calling such functions. If you don’t, it will be as if you didn’t call the function! We recommend taking a look at this primer on async functions.

The details of how async is implemented in Rust is fairly advanced and not required for this assignment, but if you are curious, here are some resources you can read:

You will also encounter Rust’s Result type, which is used for error handling. To learn more, you can take a look at Rust’s error handling tutorial