Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Real-Time with Flowdock
Search
lautis
March 28, 2012
Programming
2
190
Real-Time with Flowdock
lautis
March 28, 2012
Tweet
Share
More Decks by lautis
See All by lautis
Architecture with NoSQL: Experiences of a SaaS startup
lautis
4
730
Other Decks in Programming
See All in Programming
エラーって何種類あるの?
kajitack
5
290
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
1
650
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
260
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
130
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
470
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
330
エンジニア向け採用ピッチ資料
inusan
0
160
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
330
設計やレビューに悩んでいるPHPerに贈る、クリーンなオブジェクト設計の指針たち
panda_program
6
1.2k
都市をデータで見るってこういうこと PLATEAU属性情報入門
nokonoko1203
1
560
KotlinConf 2025 現地で感じたServer-Side Kotlin
n_takehata
1
230
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
210
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
It's Worth the Effort
3n
184
28k
Raft: Consensus for Rubyists
vanstee
140
7k
Unsuck your backbone
ammeep
671
58k
Agile that works and the tools we love
rasmusluckow
329
21k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
Documentation Writing (for coders)
carmenintech
71
4.9k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
The Invisible Side of Design
smashingmag
299
51k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
33
5.9k
Optimizing for Happiness
mojombo
379
70k
Transcript
Real-Time with Thursday, March 15, 12
@lautis Thursday, March 15, 12
“There’s no time like real-time” Thursday, March 15, 12
Demo Thursday, March 15, 12
Stream changes from backend And send messages Thursday, March 15,
12
Thursday, March 15, 12
Long-polling XHR-streaming HTMLFile WebSocket Server-Sent Events JSONP streaming XHR multipart
Thursday, March 15, 12
3 implementations with 7 transports Thursday, March 15, 12
Long-polling Thursday, March 15, 12
Long-polling HTTP/1.1 200 OK Content-Type: application/json; Thursday, March 15, 12
Long-polling HTTP/1.1 200 OK Content-Type: application/json; [{'content': 'json'}] Thursday, March
15, 12
XHR-streaming Thursday, March 15, 12
XHR-streaming HTTP/1.1 200 OK Thursday, March 15, 12
XHR-streaming HTTP/1.1 200 OK {'content': 'json'} Thursday, March 15, 12
XHR-streaming HTTP/1.1 200 OK {'content': 'json'} {'content': 'json'} Thursday, March
15, 12
XHR-streaming HTTP/1.1 200 OK {'content': 'json'} {'content': 'json'} {'content': 'json'}
Thursday, March 15, 12
Server-Sent Events Thursday, March 15, 12
Server-Sent Events HTTP/1.1 200 OK Content-Type: text/event-stream Thursday, March 15,
12
Server-Sent Events HTTP/1.1 200 OK Content-Type: text/event-stream data: {'content': 'json'}
Thursday, March 15, 12
Server-Sent Events HTTP/1.1 200 OK Content-Type: text/event-stream data: {'content': 'json'}
id: 2 data: {'content': 'json'} Thursday, March 15, 12
Server-Sent Events HTTP/1.1 200 OK Content-Type: text/event-stream data: {'content': 'json'}
id: 2 data: {'content': 'json'} Sent to server on reconnect Thursday, March 15, 12
In JavaScript var es = new EventSource('/events'); es.onmessage = function
(e) { console.log(JSON.parse(e.data)); }; Thursday, March 15, 12
Built-in in modern browsers Thursday, March 15, 12
No IE Thursday, March 15, 12
No Android Thursday, March 15, 12
Use shim instead https://github.com/Yaffle/EventSource Thursday, March 15, 12
Streams are unidirectional Thursday, March 15, 12
Sockets are bidirectional Thursday, March 15, 12
WebSockets var socket = new WebSocket('/socket'); socket.onmessage = function (e)
{ console.log(JSON.parse(e.data)); }; Thursday, March 15, 12
WebSockets var socket = new WebSocket('/socket'); socket.onmessage = function (e)
{ console.log(JSON.parse(e.data)); }; socket.onopen = function() { var m = {'content': 'json'}; socket.send(JSON.stringify(m)); } Thursday, March 15, 12
Caveats Thursday, March 15, 12
Caveats •Limited browser support Thursday, March 15, 12
Caveats •Limited browser support •Proxy problems Thursday, March 15, 12
Caveats •Limited browser support •Proxy problems •Safari crashes when used
with Proxy Auto-Configuration Thursday, March 15, 12
Socket.IO “It's care-free realtime 100% in JavaScript.” Thursday, March 15,
12
Bugs Thursday, March 15, 12
•Reconnection race-conditions Bugs Thursday, March 15, 12
•Reconnection race-conditions •Infinite loops with XHR-polling Bugs Thursday, March 15,
12
•Reconnection race-conditions •Infinite loops with XHR-polling •DOM Exception 11 Bugs
Thursday, March 15, 12
Socket.IO “It's care-free realtime 100% in JavaScript.” care-free Thursday, March
15, 12
Socket.IO “It's care-free realtime 100% in JavaScript.” Thursday, March 15,
12
Why bother? Thursday, March 15, 12
Science! It Works, Bitches. Thursday, March 15, 12
Latency matters Thursday, March 15, 12
Round-trip latency Thursday, March 15, 12
Round-trip latency Ping XHR-streaming WebSocket 0 75 150 225 300
Thursday, March 15, 12
Round-trip latency Ping XHR-streaming WebSocket 0 75 150 225 300
Thursday, March 15, 12
Round-trip latency Ping XHR-streaming WebSocket 0 75 150 225 300
Thursday, March 15, 12
Round-trip latency Ping XHR-streaming WebSocket 0 75 150 225 300
Thursday, March 15, 12
Real-world metrics from Flowdock Thursday, March 15, 12
96% use WebSockets Thursday, March 15, 12
96% use WebSockets No Flash fallback Thursday, March 15, 12
3% have obsolete browsers Thursday, March 15, 12
1% have network issues Thursday, March 15, 12
1% have network issues (or have disabled WebSockets) Thursday, March
15, 12
Network still sucks Thursday, March 15, 12
Render optimistically Thursday, March 15, 12
Basic operations in Flowdock Thursday, March 15, 12
1.Post new stuff Basic operations in Flowdock Thursday, March 15,
12
1.Post new stuff 2.Receive new stuff Basic operations in Flowdock
Thursday, March 15, 12
1.Post new stuff 2.Receive new stuff 3.Modify existing stuff Basic
operations in Flowdock Thursday, March 15, 12
Posting messages Thursday, March 15, 12
•Clients process messages as much as possible Posting messages Thursday,
March 15, 12
•Clients process messages as much as possible •Server adds unique
ID and timestamp to data Posting messages Thursday, March 15, 12
•Clients process messages as much as possible •Server adds unique
ID and timestamp to data •Message echoed to client Posting messages Thursday, March 15, 12
SUP LOL Order sync Thursday, March 15, 12
SUP LOL FOO Order sync Thursday, March 15, 12
SUP LOL FOO BAR Order sync Thursday, March 15, 12
SUP LOL FOO BAR Order sync Thursday, March 15, 12
SUP LOL FOO BAR FOO Order sync Thursday, March 15,
12
SUP LOL FOO BAR FOO Order sync Thursday, March 15,
12
Modifying stuff •Add/remove tag to message •Mark message as deleted
Thursday, March 15, 12
"Operation, which can be applied multiple times without changing the
result beyond the initial application." Idempotent changes Thursday, March 15, 12
Error handling is tricky Thursday, March 15, 12
Protips •Socket.IO will bite you •SSE is safe choice for
streaming •Design for broken internet Thursday, March 15, 12
Thanks! Thursday, March 15, 12