Things worth reading: Some resources about Protocol Buffers in #golang and #gRPC

By | November 1, 2019

Looking around microservice communication protocols I discovered protocol buffers and gRPC as a new alternative to REST with XML or JSON.

XML is used in standards like ISO 20022 for financial messages, JSON is widely used by all the new APIs in fintech (Stripe, TransferWise, lots of PSD2 API implementation of banks etc.)

Both of the above formats are very descriptive and human readable but sometimes too bloated for the scope.

What if I need to exchange messages between my own internal micro-services, or in a semi-closed environment where I may have mixed implementations for micro-services ?

In this case I want performance, a minimal data load on the exchanged data, but still keep it in a standardized way. Protocol buffers seems to be the right choice.

One of the best introduction to protocol buffers and the motivation on using them is the following post “Practical Golang: Using Protobuffs by Jacob Martin”. It presents how easy is to work with them and gives a nice benchmark comparison with XML and JSON.

After you are sold to protocol buffers the next step is gRPC.

As described on the official support site

Why gRPC?gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services.

Basically gRPC is the open source implementation from Google of a RPC protocol using protocol buffers as the native way of exchanging data in RPC calls.

For a deep dive on gRPC using golang I recommend the following article “gRPC Go: Beyond the basics” It offers a deep dive into the gRPC features beyond the simple example cases from the manuals.

There are some nice interesting features discussed as:

  • Securing gRPC based services
  • Adding middle-ware: write interceptors to add logging and basic authentication to gRPC calls.

There are two additional posts I found useful, that are basically based on the above posts:

Building High Performance APIs In Go Using gRPC And Protocol Buffers

and

Writing gRPC Interceptors in Go

What is also an interesting feature not discussed above is that gRPC has a native health-check mechanism. This is very useful if your micro-services are running in a Kubernets or Docker Swarm platform.

The article “Health checking gRPC servers on Kubernetes” does a nice introduction to native gRPC health-check . See also the repo associated with the article

I hope I sparked your interest in protocol buffers and gRPC.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.