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
710
Other Decks in Programming
See All in Programming
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
740
Kaigi on Railsに初参加したら、その日にLT登壇が決定した件について
tama50505
0
130
良いユニットテストを書こう
mototakatsu
11
3.5k
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
800
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
230
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
130
return文におけるstd::moveについて
onihusube
1
1.4k
ISUCON14感想戦で85万点まで頑張ってみた
ponyo877
1
160
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
210
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
330
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
270
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
350
Featured
See All Featured
Code Review Best Practice
trishagee
65
17k
Building Applications with DynamoDB
mza
92
6.1k
Designing Experiences People Love
moore
139
23k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Into the Great Unknown - MozCon
thekraken
34
1.6k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The Invisible Side of Design
smashingmag
299
50k
Gamification - CAS2011
davidbonilla
80
5.1k
GraphQLとの向き合い方2022年版
quramy
44
13k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Measuring & Analyzing Core Web Vitals
bluesmoon
5
190
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