How we use gRPC to build a client/server system in Go

This post is a technical presentation on how we use gRPC (and Protobuf) to build a robust client/server system.

I won’t go into the details of why we chose gRPC as the main communication protocol between our client and server, a lot of great posts already cover the subject (like this one, this one or this one). But just to get the big picture: we are building a client-server system, using Go, that needs to be fast, reliable, and that scales (thus we chose gRPC). We wanted the communication between the client and the server to be as small as possible, as secure as possible and fully compliant with both ends (thus we chose Protobuf).

We also wanted to expose another interface on the server side, just in case we add a client that has no compatible gRPC implementation: a traditional REST interface. And we wanted that at (almost) no cost.


We will start building a very simple client/server system, in Go, that will just exchange dummy messages. Once both communicate and understand each other, we’ll add extra features, such as TLS support, authentication, and a REST API.

The rest of this articles assumes you understand basic Go programming. It also assumes that you have protobuf package installed, and the protoccommand available (once again, many posts cover that topic, and there’s the official documentation).
You will also need to install Go dependencies, such as the go implementation for protobuf, and grpc-gateway.

All the code shown in this post is available at So feel free to get the repository, and use the tags to navigate in it. The repository should be placed in the src folder of your $GOPATH:

  1. $ go get -v -d
  2. $ cd $GOPATH/src/

Defining the protocol

git tag: init-protobuf-definition

First of all, you need to define the protocol, i.e. to define what can be said between client and server, and how. This is where Protobuf comes into play. It allows you to define two things: Services and Messages. A service is a collection of actions the server can perform at the client’s request, a messageis the content of this request. To simplify, you can say that service defines actions, while message defines objects.

Write the following in [api/api.proto](

  1. syntax = "proto3";
  2. package api;
  3. message PingMessage {
  4. string greeting = 1;
  5. }
  6. service Ping {
  7. rpc SayHello(PingMessage) returns (PingMessage) {}
  8. }
ft_authoradmin  ft_create_time2017-10-29 17:43
 ft_update_time2017-10-29 17:48