I’ve recently been diving deeper into gRPC, having used it peripherally in another project. Wanting a solid foundation, I explored several resources, ultimately choosing “gRPC Up and Running” (2020) by Danesh Kuruppu. I initially tried “gRPC Microservices in Go (2023),” but found it leaned heavily into microservice architecture principles before explaining gRPC itself. While the architecture discussion was interesting, it felt a bit distracting for someone that picked out the book to learn gRPC.

Why Consider gRPC?

gRPC is a high-performance, efficient protocol and interface definition language that enables you to generate server, client, and data model components. While the protocol definition is strict (requiring careful ordering), this contributes to its robustness and performance. Recent additions like “unknown fields” are beginning to address some of the flexibility concerns.

There are several key benefits to using gRPC:

  • Flexible Connection Models: Unlike REST, gRPC supports a wider range of connection options (unary, server streaming, client streaming, and bidirectional streaming).
  • Code Generation: The Interface Definition Language (IDL) allows you to generate client and server code from a single definition, reducing boilerplate and ensuring consistency. In 2020+ no one should be writing server side or client side code from hand.
  • Tooling and Language Support Protobuffers (The underlying IDL) has a large ecosystem of support, usage, and language support.
  • Performance: gRPC utilizes Protocol Buffers for serialization, resulting in a compact, binary format that’s faster to transmit and parse compared to text-based formats like JSON.]**
  • REST Support If your client absolutely had to communicate with JSON, there’s a GRPC proxy that can do the translation from a gRPC service to an REST compatible communication.

Encountering Outdated Code

The second chapter of “gRPC Up and Running” introduces a sample product service that demonstrates adding and querying products. Unfortunately, I found the provided code and tooling to be significantly outdated and difficult to compile. Dependency issues and incompatibilities required substantial updates and distractions to get the example running.

To help others avoid these hurdles, I’ve created an updated and working version of the sample code, available at: monksy/getting-started-with-grpc.

The original sample code can be found here: grpc-up-and-running/samples

Key Updates to the Sample Code:

  • Automated The Code Generation: Added a Makefile to streamline the protocol buffer code generation process.
  • go vet Integration: Incorporated go vet to improve code quality and catch potential errors. Fixing the line status.Errorf(codes.Internal, "Error while generating Product ID:", err) with the formatter code %v at the end of the message.
  • Local Module References: Configured go.mod files to reference local modules, simplifying setup and removing the need to publish to GitHub.
  • Updated Dependencies: Updated gRPC dependencies to the latest versions.
  • go_package Definition In the Protobufs: Added a go_package declaration to the product_info.proto file, required for newer protobuf definitions.
  • Revised Protobuf Command: Updated the protoc command in the Makefile to reflect the newer expectations of the protobuf compiler.
  • grpccurl Instructions: Added instructions to the README demonstrating how to verify the server is running using grpccurl.
  • Created an output folder for the binaries The Makefile outputs all the binaries to target/server|client/
  • GitLab CI Integration: Included a GitLab CI script for automated building and testing.

While “gRPC Up and Running” provides a good conceptual overview, the code examples are somewhat dated. I hope this updated repository helps you get started quickly with gRPC. Feel free to contribute and share your feedback!