Beyond JSON - An Introduction to FlatBuffers

43
Maxim Zaks Beyond JSON - An Introduction to FlatBuffers

Transcript of Beyond JSON - An Introduction to FlatBuffers

Page 1: Beyond JSON - An Introduction to FlatBuffers

Maxim Zaks

Beyond JSON - An Introduction to FlatBuffers

Page 2: Beyond JSON - An Introduction to FlatBuffers

Agenda

• About me

• The Why and How of Data Serialisation

• Deep dive into FlatBuffers

Page 3: Beyond JSON - An Introduction to FlatBuffers

RESI News - Nachrichten, die Spaß machen

Page 4: Beyond JSON - An Introduction to FlatBuffers
Page 5: Beyond JSON - An Introduction to FlatBuffers
Page 6: Beyond JSON - An Introduction to FlatBuffers

VS.

Page 7: Beyond JSON - An Introduction to FlatBuffers

Why do we need data serialisation?

• Persisting State

• Machine to Machine Communication

• Representation of Configuration

Page 8: Beyond JSON - An Introduction to FlatBuffers

How can we persist data on mobile?

• Custom binary representation

• Language provided binary serialisation

• Text based representation

• CSV, XML, JSON, YAML

• Embedded SQL or NoSQL DB

• Binary cross platform serialisation library

• FlatBuffers, Protocol Buffers, Cap’n Proto, SBE, Apache Thrift

Page 9: Beyond JSON - An Introduction to FlatBuffers

Important criteria for persisting data

• Size on disk

• Speed of read & write / partial read / memory consumption

• Human readable and writable

• Support of OO language type system

• Data versioning / evolution / migration

Page 10: Beyond JSON - An Introduction to FlatBuffers

VS.

Page 11: Beyond JSON - An Introduction to FlatBuffers

JSON

• Size on disk 👍👎

• Speed of read & write / partial read / memory consumption 👎

• Human readable and writable 👍 👍

• Support of OO language type system 👍👎

• Data versioning / evolution / migration 👍👎

Page 12: Beyond JSON - An Introduction to FlatBuffers

FlatBuffers

• Size on disk 👍👎

• Speed of read & write / partial read / memory consumption 👍 👍

• Human readable and writable 👍👎

• Support of OO language type system 👍 👍

• Data versioning / evolution / migration 👍 👍

Page 13: Beyond JSON - An Introduction to FlatBuffers

JSON FlatBuffers

size on disk 👍👎 👍👎

read & write performance 👎 👍👍

human readable & writable 👍👍 👍👎

typed API 👍👎 👍👍

multi version support 👍👎 👍👍

Page 14: Beyond JSON - An Introduction to FlatBuffers

But what about sending data?

Page 15: Beyond JSON - An Introduction to FlatBuffers

Important criteria for sending data

• Size on disk wire

• Speed of read & write / partial read / memory consumption

• Human readable and writable

• Support of OO language type system

• Data versioning / evolution / migration

Page 16: Beyond JSON - An Introduction to FlatBuffers

Enough theorylet’s do some practice

Page 17: Beyond JSON - An Introduction to FlatBuffers

FlatBuffers IDL

Page 18: Beyond JSON - An Introduction to FlatBuffers

./flatc -n person.fbs

Page 19: Beyond JSON - An Introduction to FlatBuffers

FlatBuffers Schema Editor

Page 20: Beyond JSON - An Introduction to FlatBuffers

FlatBuffers IDL

Page 21: Beyond JSON - An Introduction to FlatBuffers

FlatBuffers IDL

Page 22: Beyond JSON - An Introduction to FlatBuffers

FlatBuffers IDL

Page 23: Beyond JSON - An Introduction to FlatBuffers

FlatBuffers IDL

Page 24: Beyond JSON - An Introduction to FlatBuffers
Page 25: Beyond JSON - An Introduction to FlatBuffers
Page 26: Beyond JSON - An Introduction to FlatBuffers
Page 27: Beyond JSON - An Introduction to FlatBuffers
Page 28: Beyond JSON - An Introduction to FlatBuffers
Page 29: Beyond JSON - An Introduction to FlatBuffers
Page 30: Beyond JSON - An Introduction to FlatBuffers

What does it all mean in practice?

Page 31: Beyond JSON - An Introduction to FlatBuffers

Size on disk / wire

Page 32: Beyond JSON - An Introduction to FlatBuffers

Speed of read, writeand memory allocation

Page 33: Beyond JSON - An Introduction to FlatBuffers
Page 34: Beyond JSON - An Introduction to FlatBuffers
Page 35: Beyond JSON - An Introduction to FlatBuffers

Partial Read

Page 36: Beyond JSON - An Introduction to FlatBuffers

• over 3M cities

• ≈200 MB

• real time search

• in memory

• from file 10x slower

Page 37: Beyond JSON - An Introduction to FlatBuffers

Human readable & writable is a manner of tooling

• ./flatc -b person.fbs person.json

• ./flatc -t person.fbs -- person.bin --raw-binary --strict-json

Page 38: Beyond JSON - An Introduction to FlatBuffers

Support of OO Language type system

Page 39: Beyond JSON - An Introduction to FlatBuffers
Page 40: Beyond JSON - An Introduction to FlatBuffers

Data is backwards & forwards compatible

Page 41: Beyond JSON - An Introduction to FlatBuffers

More information

• https://google.github.io/flatbuffers/

• https://github.com/mzaks/FlatBuffersSchemaEditor

• https://github.com/mzaks/FlatBuffersSwift

• https://twitter.com/iceX33

Page 42: Beyond JSON - An Introduction to FlatBuffers

Questions?

Page 43: Beyond JSON - An Introduction to FlatBuffers

Thank you!