Slide 1

Slide 1 text

BUILDING REAL-TIME APPLICATIONS WITH NODE.JS Serge Barysiuk CTO, Propellerz [email protected]

Slide 2

Slide 2 text

About me • CTO and co-founder at Propellerz • founded a few startups - Quote Roller, NotiNote • a big JS fan - client and server side

Slide 3

Slide 3 text

What is Node.js? • JavaScript programming environment • Uses V8 runtime (Chrome’s JS runtime) • Event driven, single threaded • Non blocking I/O

Slide 4

Slide 4 text

What is non-blocking? Synchronous I/O Thread File I/O waiting Asynchronous I/O Thread File I/O

Slide 5

Slide 5 text

What is non-blocking? Synchronous I/O Asynchronous I/O

Slide 6

Slide 6 text

How to start with Node.js? • Install Node from nodejs.org (Mac, Linux Windows) • Install NPM from npmjs.org • Run your app as

Slide 7

Slide 7 text

npm: Batteries provided

Slide 8

Slide 8 text

Simple web server

Slide 9

Slide 9 text

Real-time web In real-time world, there is no polling. Instead, there are subscriptions. Changes don't need to be pulled because they're pushed instead.

Slide 10

Slide 10 text

Non real-time web any message? response any message? response any message? response Client Server

Slide 11

Slide 11 text

Real-time web connect response response response Client Server message

Slide 12

Slide 12 text

How to achieve? History • Polling • Comet Present • WebSockets

Slide 13

Slide 13 text

Polling & Comet Using different approaches to implement streaming: Iframe Streaming, Flash Streaming, XHR Streaming, JSONP Polling • Works in old browsers • Inefficient • Hard to scale + - -

Slide 14

Slide 14 text

Web Sockets • Full-duplex communication over a TCP socket • Lightweight: no TCP handshake, no HTTP headers overhead • Only new modern browsers - + +

Slide 15

Slide 15 text

Socket.io • WebSockets transport • Fallback transports for old browsers (Flash Sockets, XHR Long Polling, JSON Pooling) • Heartbeats, timeouts and disconnection support + + +

Slide 16

Slide 16 text

Socket.io: client side

Slide 17

Slide 17 text

Socket.io: server side

Slide 18

Slide 18 text

Show me a real thing! Dots demo application http://topconf-dots.jit.su/

Slide 19

Slide 19 text

Demo app: explained Client Server connection ready * joined move * move move damage * damage damage disconnect * disconnected ...

Slide 20

Slide 20 text

Code walkthrough https://bitbucket.org/sbarysiuk/topconf-dots

Slide 21

Slide 21 text

Deploying the app... • Your own server • PaaS: appfog.com, cloudfoundry.com, heroku.com, etc. • nodejitsu.com, supports web sockets

Slide 22

Slide 22 text

Questions? Email: [email protected] Twitter: @sbarysiuk