FlatBuffers
By Google
FlatBuffers is an efficient cross-platform serialization library created by Google that lets programs access serialized data directly from a buffer without first unpacking or parsing it into in-memory objects. It generates strongly typed…
Definition
FlatBuffers is an efficient cross-platform serialization library created by Google that lets programs access serialized data directly from a buffer without first unpacking or parsing it into in-memory objects. It generates strongly typed accessor code from a schema for languages including C++, Java, Kotlin, and Rust, and is designed for latency-sensitive applications such as games and mobile apps where the overhead of a traditional deserialization step is unacceptable.
Overview
FlatBuffers addresses the cost of conventional serialization formats, where reading a message typically means parsing the entire payload into a fresh tree of objects before any field can be read. That unpack step consumes CPU time and allocates memory proportional to the message size, which is a real bottleneck for games loading level data, mobile apps parsing network responses, or systems passing large structured messages between processes at high frequency. Mechanically, FlatBuffers achieves zero-copy access by laying out serialized data in memory using the same offsets and alignment that generated accessor functions expect, so reading a field means following a vtable-style offset directly into the buffer rather than reconstructing an object graph. A schema written in FlatBuffers' own IDL defines tables, structs, and unions; the `flatc` compiler then generates per-language code that exposes typed getters over the raw bytes. Because the buffer is the data structure, a FlatBuffer can be memory-mapped from disk or received over a socket and queried immediately. Within the serialization space, FlatBuffers sits alongside Protocol Buffers, from which it inherited its schema-first design and much of its author lineage, and Cap'n Proto, which pursues a similar zero-copy goal with a different wire format and RPC layer. Compared to Protocol Buffers, FlatBuffers trades a slightly larger buffer size and less human-friendly evolution ergonomics for the ability to skip deserialization entirely. Compared to plain JSON, both offer far smaller payloads and much faster access at the cost of requiring a compiled schema and generated code. In practice, FlatBuffers is used heavily in game engines for asset and level data, in Android applications where fast startup and low memory churn matter, and in machine learning runtimes such as TensorFlow Lite, which uses FlatBuffers as its on-disk model format. It is also used in interprocess communication where messages must be read repeatedly with minimal overhead, such as browser engines and embedded systems. The main trade-offs are added build complexity from the schema-compiler step, a less forgiving mutation model since buffers are optimized for reading rather than in-place editing, and a learning curve around vtables and schema evolution rules. Teams building simple request-response APIs where payload sizes are small and CPU is not the bottleneck often find plain JSON or Protocol Buffers simpler to adopt, reserving FlatBuffers for the subset of paths where deserialization cost is measurably significant. Because the format was designed with game engines in mind, its tooling around versioned schema evolution is also less polished than Protocol Buffers', which has invested heavily in backward- and forward-compatibility guarantees across large organizations with many independently deployed services.
Key Features
- Zero-copy access to serialized data without an unpacking step
- Schema-driven code generation across C++, Java, Kotlin, Rust, and more
- Compact binary wire format with optional field support for schema evolution
- Memory-mappable buffers that can be read directly from disk
- Support for both tables (flexible, evolvable) and structs (fixed, compact)
- Used as the native model format in TensorFlow Lite
- Cross-language interoperability from a single .fbs schema definition
- Optional JSON-to-FlatBuffer conversion tooling for debugging