Implementation of gRPC with Go

The module ( contains the Go language implementation of gRPC. HTTP/2 based RPC with instruction

The blog ( contains the introduction to key gRPC concepts, with an overview of gRPC architecture and RPC life cycle


This blog finds that gRPC is 25 times more performant than REST API (as defined as time to have the response for an specific API)

Protocol Buffers

The module ( contains Go bindings for Protocol Buffers

The documentation and tutorials by Google can be found at Protocol Buffers Go tutorials

My repository for Go bindings for Protocol Buffers instruction and theory can be found at

gRPC with Go

Follow the module ( to install compiler and packages supporting gRPC with Go

To generate gRPC services for your application:

  • Update your PATH so that the protoc compiler can find the plugins
  • Generate services:
    protoc --go-grpc_out=require_unimplemented_servers=false:. ./yourpath/to.protofile/*.proto

Demo Application applied gRPC with Go

The application contains:

  • The demo of 4 main types of RPCs

    • Unary RPCs
    • Server Streaming RPCs
    • Client Streaming RPCs
    • Bi-Directional Streaming RPCs
  • gRPC Error Handling

    • How gRPC deals with error can be found at
    • Reference to implementation oof error codes can be found at
    • If an application needs to return extra information on top of an error code,it can use the metadata context
  • gRPC Deadlines

    • Deadlines allow gRPC clients to specify how long they are willing to wait for an RPC to complete before the RPCis terminated with the error DEADLINE_EXCEEDED
    • The gRPC documentation recommends you set a deadline for all client RPC calls
    • Setting the Deadlines is up to you, how long do you feel your API should have to complete?
    • The server should check if the deadline has exceeded and cancel the work it is doing
    • defer cancel() calls the cancel() function when the deadline has exceeded
    • This blog describe Deadlines in depth
    • Note: Deadlines are propagated across if gRPC calls are chained
    • A => B => C (Deadline for A is passed to B and then passed to C)
  • SSL Encryption in gRPC

    • SSL encryption is done by generating SSL certificates
    • SSL allows communication to be secure end-to-end and ensuring no Man in the middle attack can be performed
    • SSL allows clients and servers to encrypt packet
    • Routers can not view the content of the internet packets
    • TLS (Transport Layer Security)
      • Successor of SSL, encrypts the connection between 2 endpoints for secure data exchange
    • Two ways of using SSL (gRPC can use both)
      • 1-way verification, e.g. browser => WebServer
      • 2-way verification, e.g. SSL authentication
    • Detailed Setup of SSL for Encryption

    • All steps and command lines are noted in file ssl/
    • All the configuration for generating SSL certificates is specified in file ssl/ssl.cnf
    • Using SHA256 algorithm for authentication
  • gRPC Reflection & CLI

    • Why gRPC Reflection?

      • As we’ve seen, for Clients to connect to our Server, they need to have a .proto file which defines the service
      • This is fine for production (we definitely want to know the API definition in advance)
      • For development, when you have a gRPC server you don’t know, we have to know what APIs the server has
      • Reflection is the solution
    • Reflection helps us

      • Having servers “expose” which endpoints are available
      • Allowing CLI to talk to our server without have a preliminary .proto file
    • This project uses the evans CLI to practice on the client side

    • To register server reflection on a gRPC server:

      import ""
      s := grpc.NewServer()
      pb.RegisterYourOwnServer(s, &server{})
      // Register reflection service on gRPC server.
    • More information about gRPC Reflection can be found at

  • How to run the project

    • The project contains services
      • Greeting Service
      • Calculator Service
    • Start the server of one service
      go run service/service_server/server.go
    • Start the client of one service
      go run service/service_client/client.go


  • Minh Tran (Me)


View Github