My thoughts on gRPC

29/05/2020 19:36 BST

Recently I’ve been trying out gRPC on the first impression, it was really fun to work with, once I the hang of writing a .proto file and using the code generator protoc, all I had to do was implement the interface (the one with the Server suffix) which I find very easy to do with the IDE of my choice (GoLand), just of the case of pressing Alt+Enter and then implementing interface it’s generate the spoiler plates for you so you don’t have to write them yourself; once I got past that, and I got the microservices all up and running, all I had to do was set up the client and execute the method, I didn’t even have to think about serialization as protoc will take care of that for you which is very nice, all I had to do was write the .proto file.

I do have an example of gRPC at , I just wanted to get a feel of writing microservices.

At work, I have worked with large JSON REST API, I had to write and as silly as it sounds an XML file to aid in deserialization of JSON, I am not going to lie, it’s just plain stupid and was not fun at all, a real pain to debug as well, here is an example.

<?xml version="1.0" encoding="UTF-8" ?>
    <class name="Data" exclusion-policy="ALL">
        <property name="leg" serialized-name="leg" type="integer" expose="true" />
        <property name="references" serialized-name="references" expose="true">

Then here another example of the Go counterpart to the above.

type Data struct {
	Leg        int64    `json:"leg"`
	References []string `json:"references"`

And the same for .proto

message Data {

    int64 leg = 1;

    repeated string references = 2;


As you can see it’s not as painful as writing it in XML. But with gRPC, I don’t even have to think about serialization as I mentioned earlier. You might want to check out it converts JSON into gorgeous, typesafe code in any language, so you don’t have to do things the hard way. (They don’t support PHP at the time of this writing.)

One could argue, I should have used PHP’s json_encode and json_decode, no that terrible with large data structures, but that will be another story to tell.

I can see myself using gRPC for communication between the back-office app server and individual CLI applications to use with CRON, I believe that will be the better approach compared to Symfony’s one size fits all bin/console.

| |

Privacy Policy | CV