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
CSC509 Lecture 03
javiergs
PRO
0
330
ポスターセッション: 「まっすぐ行って、右!」って言ってラズパイカーを動かしたい 〜生成AI × Raspberry Pi Pico × Gradioの試作メモ〜
komofr
0
970
GitHub Actions × AWS OIDC連携の仕組みと経緯を理解する
ota1022
0
240
ИИ-Агенты в каждый дом – Алексей Порядин, PythoNN
sobolevn
0
150
Local Peer-to-Peer APIはどのように使われていくのか?
hal_spidernight
2
450
そのpreloadは必要?見過ごされたpreloadが技術的負債として爆発した日
mugitti9
2
3k
猫と暮らすネットワークカメラ生活🐈 ~Vision frameworkでペットを愛でよう~ / iOSDC Japan 2025
yutailang0119
0
220
あなたの知らない「動画広告」の世界 - iOSDC Japan 2025
ukitaka
0
400
Advance Your Career with Open Source
ivargrimstad
0
350
CSC305 Lecture 04
javiergs
PRO
0
250
なぜGoのジェネリクスはこの形なのか? Featherweight Goが明かす設計の核心
ryotaros
7
1k
タスクの特性や不確実性に応じた最適な作業スタイルの選択(ペアプロ・モブプロ・ソロプロ)と実践 / Optimal Work Style Selection: Pair, Mob, or Solo Programming.
honyanya
3
140
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
246
12k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Building an army of robots
kneath
306
46k
How to Think Like a Performance Engineer
csswizardry
27
2k
Visualization
eitanlees
148
16k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
The Language of Interfaces
destraynor
162
25k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
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