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 Web Application with Socket.IO, Node....
Search
York Tsai
May 19, 2013
Programming
10
3.6k
Real-time Web Application with Socket.IO, Node.js, and Redis
From JSDC 2013
York Tsai
May 19, 2013
Tweet
Share
More Decks by York Tsai
See All by York Tsai
Redis - From LAMP to NOSQL
yorktsai
0
300
Other Decks in Programming
See All in Programming
ワープロって実は計算機で
pepepper
2
1.4k
パスタの技術
yusukebe
1
530
Claude Codeで挑むOSSコントリビュート
eycjur
0
180
サーバーサイドのビルド時間87倍高速化
plaidtech
PRO
0
650
為你自己學 Python - 冷知識篇
eddie
1
280
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
330
Understanding Ruby Grammar Through Conflicts
yui_knk
1
140
Portapad紹介プレゼンテーション
gotoumakakeru
1
130
ECS初心者の仲間 – TUIツール「e1s」の紹介
keidarcy
0
110
未来を拓くAI技術〜エージェント開発とAI駆動開発〜
leveragestech
2
190
学習を成果に繋げるための個人開発の考え方 〜 「学習のための個人開発」のすすめ / personal project for leaning
panda_program
1
110
CSC305 Summer Lecture 12
javiergs
PRO
0
130
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
830
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
110
20k
BBQ
matthewcrist
89
9.8k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.8k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Thoughts on Productivity
jonyablonski
69
4.8k
Art, The Web, and Tiny UX
lynnandtonic
302
21k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Become a Pro
speakerdeck
PRO
29
5.5k
It's Worth the Effort
3n
187
28k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Transcript
Real-time Web Application with Socket.IO, Node.js, and Redis York Tsai,
JSDC 2013
Who is York • http://www.linkedin.com/pub/york-tsai/13/bb/8a8 • https://twitter.com/yorktsai • https://www.facebook.com/yorktsai •
VP Engineering @ EZTABLE
Never Live Demo! • http://jsdc.york.tw/ • I hope this work
on my (and yours) computer ...
None
You may Have Heard About • Forever Iframe • XMLHttpRequest
Long Polling • Cometd • Websocket • http://en.wikipedia.org/wiki/Comet_(programming ) • TL;DR
Socket.IO • Cross browser (including IE 6) • Real-time and
bi-directional persistent connection (WebSocket) • Very simple to use • Javascript!
Start a Server
Sending and Receiving Events
None
Select Receivers for Events
Broadcasting
Rooms
Single Target
Multiple Applications?
Namespacing
How About New Connections?
Data Persistence • Need a persistence layer • Get data
from the persistence layer whenever a new connection established
Integration I have component X,Y,Z want to send/receive data from
user's browser
Pub/Sub or Message Queue Messaging system usually supports both
Pub/Sub Digram from Python's Website
Redis • Super-fast in-memory data structure server • Pub/Sub •
Rich client libraries • Zero install and easy to operate
3 Commands • SUBSCRIBE channel • UNSUBSCRIBE channel • PUBLISH
channel message
In addition... • Connect multiple node.js server to one redis
channel • Scalability!
Two Connections per Server
Redis-backed Pub/Sub • Two clients required: one for pub, one
for sub • Use one channel, add metadata to your message
Redis-backed Pub/Sub
Frequently Asked Questions
SSL? Yes!
SSL Server
SSL Client
Cross domain? Yes! (If use WebSocket or JSONP)
Authentication?
Authentication • Cookie & Session • Cookie does not cross
domain, use SSL + Access Token instead
Load Balancing? Yes! (If use Nginx >= 1.3.13)
Sample Nginx Configuration
Load Balancing using ELB • ELB (Elastic Load Balancer)'s HTTP(S)
proxy does not understand websocket requests • Use TCP/SSL, instead of HTTP/HTTPS • No session stickyness • No X-Forwarded-For header
Scalability • Single thread • 2500~3500 connections per process •
As many processes as you want
Configurations • store (default: MemoryStore, single process only) • transports
(default: websocket, htmlfile, xhr- polling, jsonp-polling) • authorization (default: false)
Configurations - transports
Thank You! The slide is also the live demo itself.
Please check the following repo! https://github.com/yorktsai/jsdc2013