Slide 1

Slide 1 text

An Interlude by Quentin Cheshire Proudly Representing West RTC Message Passing vs. Data Synchronization

Slide 2

Slide 2 text

whoami?

Slide 3

Slide 3 text

What’s all this fuss about? was all the rage... ...which evolved into Long-polling lovingly known as “Comet” WebSockets Lo and Behold! Introducing... Data Channels

Slide 4

Slide 4 text

Why Bother? Users don’t like waiting Are obsolete The Realtime Web is Here!

Slide 5

Slide 5 text

How will you use the force? It’s just a messaging channel!

Slide 6

Slide 6 text

Have you thought this through? Persistence Fault Tolerance Scaling Consistency Security

Slide 7

Slide 7 text

Message Passing is a Primitive Are better tools in order? “All problems in computer science can be solved by another level of indirection abstraction”

Slide 8

Slide 8 text

Data Synchronization Most apps observe and modify data That data reflects state Your API should be built around this!

Slide 9

Slide 9 text

An Example: Chat var channel = new MessageChannel(); channel.subscribe(function(msg) { receivedNewMessage(msg); }); function sendMsg(msg) { channel.send(msg); } var dataStore = new DataStore(); dataStore.on("new_row", function(msg) { receivedNewMessage(msg); }); function sendMsg(msg) { dataStore.addRow(msg); }

Slide 10

Slide 10 text

An Example: Chat var dataStore = new DataStore().limit(10); dataStore.on("new_row", function(msg) { receivedNewMessage(msg); }); function sendMsg(msg) { dataStore.addRow(msg); } Archival

Slide 11

Slide 11 text

An Example: Chat var dataStore = new DataStore(); dataStore.on("new_row", function(msg) { receivedNewMessage(msg); }); function sendMsg(msg) { dataStore.addRow(msg); } Fault Tolerance

Slide 12

Slide 12 text

An Example: Chat var dataStore = new DataStore(); dataStore.on("new_row", function(msg) { receivedNewMessage(msg); }); function sendMsg(msg) { dataStore.addRow(msg); } Security { ".read": "msg.to == auth.id" }

Slide 13

Slide 13 text

Conceptually Simple There’s a lot of complexity in turning a stream of messages into usable state Why not just directly store state?

Slide 14

Slide 14 text

More Efficient You have the flexibility to combine operations New clients only care about the latest state 1 → 2 → 3 → 4 → 5

Slide 15

Slide 15 text

Automatic Merge Behavior Conflicts will typically require several messages to resolve With a data abstraction, it can be a core primitive

Slide 16

Slide 16 text

Data Sync not Message Passing Don’t let the primitives dictate how your application code is structured. Build the abstractions you need (Or use one of the available ones!) Store state - don’t pass messages (Except when that’s really what you want to do) Thank you! www github twitter email kix.in anantn @anantn anant@firebase.com