why use protocol buffers in java

Recently,I read code of HBase.I find client use protobuf to communicate with server in HBase's code.

Java has "Serializable". why not use it?

Jon Skeet
people
quotationmark

  • Efficiency: protocol buffers are generally much more efficient at transmitting the same amount of data than Java binary serialization
  • Portability: Java binary serialization is not widely implemented outside Java, as far as I'm aware (unsurprisingly)
  • Robustness in the face of unrelated changes: unless you manually specify the serializable UUID, you can end up making breaking changes without touching data at all in Java. Ick.
  • Backward and forward compatiblity: old code can read data written by new code. New code can read data written by old code. (You still need to be careful, and the implications of changes are slightly different between proto2 and proto3, but basically protobuf makes this a lot easier to reason about than Java.)
  • It's a lot easier to accidentally introduce non-serializable members into Java binary serialization, as proto descriptor files are all about serialization... you can't refer to an arbitrary class, etc.

I've worked on projects using protocol buffers, and I've worked on projects using Java binary serialization - and I would be very reluctant to use the latter again...

people

See more on this question at Stackoverflow