Java serialization

Redis usage of generic jackson serializer (158Mb space was used for 50k keys)

Screenshot 2021-11-21 at 6 16 31 PM

Redis usage of protobuf serializer (48Mb space was used for the same 50K keys)

Screenshot 2021-11-21 at 9 51 04 PM

How does GenericJackson2Json serialization work:

When a java POJO is serialized, the following are the steps involved

  • Add metadata of the class associated with the object, meta information will be the entire package name and the class name.
  • If there are any superclasses, metadata will be added recursively until we find the Object class
  • The purpose of adding the package name and the class name as meta is to help in deserialization.

Screenshot 2021-11-24 at 9 32 41 PM

  • In the above image, we can see the metadata information that is appended as part of GenericJackson2Json serializer, such as @class, java.util.ImmutableCollections.List.
  • In this example, College contains List and every teacher object contains List, so for every teacher and student, this meta-information will be occupying additional space.

How does ProtoBuf serialization work:

refer: https://developers.google.com/protocol-buffers

In protocol buffers, the transmission of data is done in binary format. Because of this it is faster and saves space. The protobuf (protocol buffers) consist of context file (.proto file)

{ string name = 1; string address = 2; }

Screenshot 2021-11-24 at 10 06 15 PM

The protobuf doesn’t main the order, so field numbers are used for deserializtion.

Another major advantage of using protobuf is that, the SDK will be able to generate code for other languages as well.

TODO: Add a golang example, of fetching values from redis using prtobuf