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
670
Other Decks in Programming
See All in Programming
Random\Randomizer クラスで日常のあれこれを解決しよう! / Random\Randomizer class solves familiar trouble
cocoeyes02
0
250
Polars入門
daikikatsuragawa
1
100
雑に思考を整理する技術と効能
konifar
60
29k
MicrosoftのPlatform Engineeringガイドを読んで実際になにかやってみた
ymd65536
1
340
TCAとKMPを用いた新規動画配信アプリ 「ABEMA Live」の設計
tomu28
1
110
AWS CDKコントリビュートTIPS / aws-cdk-contribution-tips
gotok365
2
200
Blue/Greenデプロイの導入による 運用フローの改善
kudoas
1
380
Zero Waste, Radical Magic, and Italian Graft – Quarkus Efficiency Secrets
hollycummins
0
230
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
7
930
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
1
1k
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
960
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
140
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
225
17k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
2
1.3k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
274
13k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
25
2.3k
Large-scale JavaScript Application Architecture
addyosmani
504
110k
In The Pink: A Labor of Love
frogandcode
138
21k
GraphQLとの向き合い方2022年版
quramy
32
12k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
What’s in a name? Adding method to the madness
productmarketing
PRO
16
2.6k
Build The Right Thing And Hit Your Dates
maggiecrowley
24
2k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
322
20k
Building an army of robots
kneath
300
41k
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