Search code examples
flatbuffers

Flatbuffer: Compatibility of runtime and compiler


Are Flatbuffers compatible across different versions of the Flatbuffer compiler + runtime libraries?

I've spent a many hours troubleshooting this and think I've identified that the answer is "NO", but still haven't found an authoritative answer. The docs are mum on this.

For example:

  • Generate code (Java/Go) using flatc from v1.11
  • Use the generated code to write and read on another application that is using the runtime dependencies from v1.10 (the reading is technically only because of local unit tests).

If this is the case, then I'd love to have some clarification on the compiler/runtime upgrade story. Perhaps my issue is the fact that I'm writing with a higher version than what I'm reading with - hence, the upgrade story might be to always upgrade readers first, then roll out writer upgrades.


Solution

  • FlatBuffers (the actual binary, serialized buffers / files) are forwards and backwards compatible across all languages, platforms and versions, by design. You can thus upgrade code that reads or writes these buffers in any order, without ever running into format compatibility issues.

    The code generated by a particular version of flatc for a particular language, however, must be compiled against the runtime of exactly that same version. The generated code and the runtime are very closely tied for a system as low-level as FlatBuffers, so it is not possible to ensure the API between the two stays stable across all versions. This is purely a code compilation issue, however, should not affect serialized data.

    You should not de-couple the two. If you are shipping code that relies on generated code, you need to ensure the project contains the matching runtime as well, rather than relying on external runtime that may already be present on a users system, or whatever.

    Java recently gained changes to ensure people don't mismatch runtimes, though that was not present in 1.10.