Real-time Web Application with Socket.IO, Node.js, and Redis

28,672 views

Published on

JSDC 2013

Published in: Technology
1 Comment
35 Likes
Statistics
Notes
No Downloads
Views
Total views
28,672
On SlideShare
0
From Embeds
0
Number of Embeds
26
Actions
Shares
0
Downloads
300
Comments
1
Likes
35
Embeds 0
No embeds

No notes for slide

Real-time Web Application with Socket.IO, Node.js, and Redis

  1. 1. Real-time Web Application with Socket.IO, Node.js, and Redis York Tsai, JSDC 2013
  2. 2. 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
  3. 3. Never Live Demo! ● http://jsdc.york.tw/ ● I hope this work on my (and yours) computer ...
  4. 4. You may Have Heard About ● Forever Iframe ● XMLHttpRequest Long Polling ● Cometd ● Websocket ● ● http://en.wikipedia.org/wiki/Comet_(programming ) TL;DR
  5. 5. Socket.IO ● ● Cross browser (including IE 6) Real-time and bi-directional persistent connection (WebSocket) ● Very simple to use ● Javascript!
  6. 6. Start a Server
  7. 7. Sending and Receiving Events
  8. 8. Select Receivers for Events
  9. 9. Broadcasting
  10. 10. Rooms
  11. 11. Single Target
  12. 12. Multiple Applications?
  13. 13. Namespacing
  14. 14. How About New Connections?
  15. 15. Data Persistence ● ● Need a persistence layer Get data from the persistence layer whenever a new connection established
  16. 16. Integration I have component X,Y,Z want to send/receive data from user's browser
  17. 17. Pub/Sub or Message Queue Messaging system usually supports both
  18. 18. Pub/Sub Digram from Python's Website
  19. 19. Redis ● Super-fast in-memory data structure server ● Pub/Sub ● Rich client libraries ● Zero install and easy to operate
  20. 20. 3 Commands ● SUBSCRIBE channel ● UNSUBSCRIBE channel ● PUBLISH channel message
  21. 21. In addition... ● ● Connect multiple node.js server to one redis channel Scalability!
  22. 22. Two Connections per Server
  23. 23. Redis-backed Pub/Sub ● ● Two clients required: one for pub, one for sub Use one channel, add metadata to your message
  24. 24. Redis-backed Pub/Sub
  25. 25. Frequently Asked Questions
  26. 26. SSL? Yes!
  27. 27. SSL Server
  28. 28. SSL Client
  29. 29. Cross domain? Yes! (If use WebSocket or JSONP)
  30. 30. Authentication?
  31. 31. Authentication ● ● Cookie & Session Cookie does not cross domain, use SSL + Access Token instead
  32. 32. Load Balancing? Yes! (If use Nginx >= 1.3.13)
  33. 33. Sample Nginx Configuration
  34. 34. 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
  35. 35. Scalability ● Single thread ● 2500~3500 connections per process ● As many processes as you want
  36. 36. Configurations ● ● ● store (default: MemoryStore, single process only) transports (default: websocket, htmlfile, xhrpolling, jsonp-polling) authorization (default: false)
  37. 37. Configurations - transports
  38. 38. Thank You! The slide is also the live demo itself. Please check the following repo! https://github.com/yorktsai/jsdc2013

×