Compressing the payload
While Protobuf serializes data into binary and this involves much smaller payloads than text data, we can apply compression on top of the binary. gRPC provides us with the gzip Compressor (https://pkg.go.dev/google.golang.org/grpc/encoding/gzip) and for more advanced use cases, lets us write our own Compressor (https://pkg.go.dev/google.golang.org/grpc/encoding).
Now, before diving into how to use the gzip Compressor, it is important to understand that lossless compression might result in a bigger payload size. If your payload does not contain repetitive data, which is what gzip detects and compresses, you will send more bytes than needed. So, you will need to experiment with a typical payload and see how gzip affects its size.
To show an example of that, I included in the helpers
folder a file called gzip.go
, which contains a helper function called compressedSize
. This function returns the original size of the serialized data and its size after gzip compression...