Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

From JSDC 2013

York Tsai

May 19, 2013
Tweet

More Decks by York Tsai

Other Decks in Programming

Transcript

  1. You may Have Heard About • Forever Iframe • XMLHttpRequest

    Long Polling • Cometd • Websocket • http://en.wikipedia.org/wiki/Comet_(programming ) • TL;DR
  2. Socket.IO • Cross browser (including IE 6) • Real-time and

    bi-directional persistent connection (WebSocket) • Very simple to use • Javascript!
  3. Data Persistence • Need a persistence layer • Get data

    from the persistence layer whenever a new connection established
  4. Redis • Super-fast in-memory data structure server • Pub/Sub •

    Rich client libraries • Zero install and easy to operate
  5. Redis-backed Pub/Sub • Two clients required: one for pub, one

    for sub • Use one channel, add metadata to your message
  6. Authentication • Cookie & Session • Cookie does not cross

    domain, use SSL + Access Token instead
  7. 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
  8. Configurations • store (default: MemoryStore, single process only) • transports

    (default: websocket, htmlfile, xhr- polling, jsonp-polling) • authorization (default: false)
  9. Thank You! The slide is also the live demo itself.

    Please check the following repo! https://github.com/yorktsai/jsdc2013