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.5k
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
あのころの iPod を どうにか再生させたい
orumin
2
2.2k
Google I/O Extended Incheon 2025 ~ What's new in Android development tools
pluu
1
250
Nuances on Kubernetes - RubyConf Taiwan 2025
envek
0
110
iOS開発スターターキットの作り方
akidon0000
0
240
リッチエディターを安全に開発・運用するために
unachang113
1
360
Android 15以上でPDFのテキスト検索を爆速開発!
tonionagauzzi
0
190
Vibe Codingの幻想を超えて-生成AIを現場で使えるようにするまでの泥臭い話.ai
fumiyakume
21
10k
書き捨てではなく継続開発可能なコードをAIコーディングエージェントで書くために意識していること
shuyakinjo
0
220
CLI ツールを Go ライブラリ として再実装する理由 / Why reimplement a CLI tool as a Go library
ktr_0731
3
1k
11年かかって やっとVibe Codingに 時代が追いつきましたね
yimajo
1
240
「次に何を学べばいいか分からない」あなたへ──若手エンジニアのための学習地図
panda_program
3
720
Vibe coding コードレビュー
kinopeee
0
420
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
184
22k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
We Have a Design System, Now What?
morganepeng
53
7.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.5k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Documentation Writing (for coders)
carmenintech
73
5k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Balancing Empowerment & Direction
lara
1
530
Large-scale JavaScript Application Architecture
addyosmani
512
110k
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