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
700
Other Decks in Programming
See All in Programming
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
350
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
650
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
200
Recoilを剥がしている話
kirik
5
7.2k
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
150
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
530
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
340
MCP with Cloudflare Workers
yusukebe
2
230
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
200
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
140
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
290
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
130
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.1k
Documentation Writing (for coders)
carmenintech
67
4.5k
Gamification - CAS2011
davidbonilla
80
5.1k
KATA
mclloyd
29
14k
Speed Design
sergeychernyshev
25
670
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
4 Signs Your Business is Dying
shpigford
182
21k
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