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
310
Other Decks in Programming
See All in Programming
Ruby x Terminal
a_matsuda
7
590
モダンOBSプラグイン開発
umireon
0
120
LangChain4jとは一味違うLangChain4j-CDI
kazumura
1
180
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
250
猫の手も借りたい!ので AIエージェント猫を作って社内に放した話 Claude Code × Container Lambda の Slack Bot "DevNeko"
naramomi7
0
260
文字コードの話
qnighy
44
17k
ロボットのための工場に灯りは要らない
watany
10
2.8k
RubyとGoでゼロから作る証券システム: 高信頼性が求められるシステムのコードの外側にある設計と運用のリアル
free_world21
0
280
How to stabilize UI tests using XCTest
akkeylab
0
120
Swift ConcurrencyでよりSwiftyに
yuukiw00w
0
260
守る「だけ」の優しいEMを抜けて、 事業とチームを両方見る視点を身につけた話
maroon8021
3
870
モックわからないマン卒業記 ~振る舞いを起点に見直した、フロントエンドテストにおけるモックの使いどころ~
tasukuwatanabe
2
280
Featured
See All Featured
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
220
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Crafting Experiences
bethany
1
86
Faster Mobile Websites
deanohume
310
31k
A Tale of Four Properties
chriscoyier
163
24k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
340
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
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