Hot questions for Using Cap'n Proto in json

Question:

Please help to suggest some merits and demerits of Flatbuffers and CBOR protocols. Both these binary formats claim to be good on their websites, but I am not able to make some good differences between the two.

Flatbuffers:

Advantage:

  1. Strict typing in FlatBuffer, Cap’n proto and other similar solutions is seen as major key point for performance since no additional encoding/decoding is necessary.
  2. The data model allows simple offsetting of typed objects with a compact data structure and fast access
  3. FlatBuffers does not need a parsing/ unpacking step to a secondary representation before you can access data often coupled with per-object memory allocation.

Disadvantage:

  1. New and not standardized like CBOR.

CBOR

Advantage:

  1. Can create and process entirely in stream with no extra memory
  2. Don’t have to pre-define any schema as our data is dynamic and variant
  3. It’s an open international standard from the IETF makes it a even better choice than a proprietary one.
  4. It’s designed for low memory, non-conversion, stream-based processing while also providing extensions for other data types

Disadvantage:

  1. CBOR says that it follows the JSON model (so not strictly typed objects)
  2. It starts with the same types of objects (strings, integers, maps, etc.).

PS: It feels like managing types in CBOR will be performance costly compared to flatbuffers, but as CBOR is standardized protocol I am inclined to prefer it if this difference is not huge. Please let me know which of two will you all recommend and why.


Answer:

I think you've already spelled it out quite clearly yourself. FlatBuffer's strength is being able to access the data without parsing/unpacking/allocation, which can give serious performance benefits in some scenarios. But if this doesn't matter to you, e.g. Protocol Buffers may work just as well.

Strong typing vs dynamic typing in data matters a lot too. I'd only use the latter if I wanted generic data storage with no constraints ahead of time.

Btw, if for some reason you prefer dynamic typing, but would also like to have the performance benefits of in-place access, there is actually a format that combines the two: https://google.github.io/flatbuffers/flexbuffers.html

FlatBuffers is not "proprietary". It may have been designed at Google, but it is open source and relied upon by many other companies.