Message Passing
vs.
Data Synchronization
Anant Narayanan

Pivotal Labs Tech Talk
May 14, 2013
Realtime Synchronization
Network

• Build apps fast without managing servers
• Data persistence, but in realtime
• With au...
Why?
• Users don’t like waiting
• Users want their data wherever they are
• Between all their devices
• And sometimes thei...
“AJAX”
Not Good Enough

• You still need to know when to fetch changes
• Or, you need to keep asking about what’s new
Long Polling
• Bidirectional channel between client & server
• Upgrade after initiating a HTTP connection
• Don’t close until you need ...
How will you use it?
PUBNUB.subscribe({
channel: "my_channel",
message: function(m){alert(m)}
});
PUBNUB.publish({
channel...
Example: Chat
var box = PUBNUB.$('box'), input = PUBNUB.$('input');
var channel = 'chat';
PUBNUB.subscribe({
channel: chan...
An Alternative Approach
var chatRef =
new Firebase('https://chat.firebaseio-demo.com/');
$('#messageInput').keypress(funct...
Why Data Synchronization?
Simpler Client Logic
There’s a lot of complexity in turning a
stream of messages into state that...
Why Data Synchronization?
Greater Efficiency

We have the flexibility to combine operations
Why Data Synchronization?
Automatic Merge Behavior
With message passing, conflict resolution can get
tricky, but with data ...
Why Data Synchronization?
Greater Flexibility
Message passing is simply a subset of
data synchronization
Example: Counter
Transactions can be a built in primitive

var countRef = new Firebase(
'https://example.firebaseio.com/co...
Example: Counter
Latency Compensation
There may be several “incorrect” intermediate steps
but the system as a whole is eventually consisten...
Thank You
Write your app logic as a function of
current state instead of deltas
Store state instead of passing messages
an...
Upcoming SlideShare
Loading in …5
×

Message Passing vs. Data Synchronization

1,896 views

Published on

A Pivotal tech talk covering the advantages and disadvantages of using a message passing approach vs. data synchronization for building modern, distributed web applications.

Video: http://pivotallabs.com/anant-narayanan-firebase/

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,896
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Message Passing vs. Data Synchronization

  1. 1. Message Passing vs. Data Synchronization Anant Narayanan Pivotal Labs Tech Talk May 14, 2013
  2. 2. Realtime Synchronization Network • Build apps fast without managing servers • Data persistence, but in realtime • With authentication & security rules, can serve as the entire backend
  3. 3. Why? • Users don’t like waiting • Users want their data wherever they are • Between all their devices • And sometimes their friends • & are quickly becoming obsolete
  4. 4. “AJAX”
  5. 5. Not Good Enough • You still need to know when to fetch changes • Or, you need to keep asking about what’s new
  6. 6. Long Polling
  7. 7. • Bidirectional channel between client & server • Upgrade after initiating a HTTP connection • Don’t close until you need to
  8. 8. How will you use it? PUBNUB.subscribe({ channel: "my_channel", message: function(m){alert(m)} }); PUBNUB.publish({ channel: "my_channel", message: "Hello World" }); var channel = pusher.subscribe('my-channel'); channel.bind('my-event', function(data) { alert('Received my-event with: ' + data.message); }); pusher.trigger('my-channel', 'my-event', { "message": "hello world" } );
  9. 9. Example: Chat var box = PUBNUB.$('box'), input = PUBNUB.$('input'); var channel = 'chat'; PUBNUB.subscribe({ channel: channel, callback: function(text) { box.innerHTML = (''+text).replace( /[<>]/g, '' ) + '<br>' + box.innerHTML; } }); PUBNUB.bind('keyup', input, function(e) { (e.keyCode || e.charCode) === 13 && PUBNUB.publish({ channel: channel, message: input.value, x: (input.value='') }); });
  10. 10. An Alternative Approach var chatRef = new Firebase('https://chat.firebaseio-demo.com/'); $('#messageInput').keypress(function(e) { (e.keyCode == 13) && chatRef.push({ name: $('#nameInput').val(), text: $('#messageInput').val() }) && $('#messageInput').val(''); }); chatRef.limit(10).on('child_added', function(s) { var message = s.val(); $('<div/>').text(message.text).prepend($('<em/>') .text(message.name+': ')) .appendTo($('#messagesDiv')); });
  11. 11. Why Data Synchronization? Simpler Client Logic There’s a lot of complexity in turning a stream of messages into state that is usable
  12. 12. Why Data Synchronization? Greater Efficiency We have the flexibility to combine operations
  13. 13. Why Data Synchronization? Automatic Merge Behavior With message passing, conflict resolution can get tricky, but with data synchronization it can be a core primitive
  14. 14. Why Data Synchronization? Greater Flexibility Message passing is simply a subset of data synchronization
  15. 15. Example: Counter Transactions can be a built in primitive var countRef = new Firebase( 'https://example.firebaseio.com/counter'); countRef.transaction(function(current_value) { return current_value + 1; });
  16. 16. Example: Counter
  17. 17. Latency Compensation There may be several “incorrect” intermediate steps but the system as a whole is eventually consistent eg: Events can always be optimistically triggered locally
  18. 18. Thank You Write your app logic as a function of current state instead of deltas Store state instead of passing messages anant@firebase.com twitter www @anantn kix.in

×