Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

http://game.rem.io

Slide 3

Slide 3 text

Real time is easy, cheap, and expected.

Slide 4

Slide 4 text

Fast Self-updating

Slide 5

Slide 5 text

Instant Self-updating

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

function updatePrices() { $.get('/prices?stock=MSFT', function (data) { renderPrices(data); setTimeout(updatePrices, 60 * 1000); }); }

Slide 8

Slide 8 text

The server is the ultimate source of truth. We want the server to push the prices to the client.

Slide 9

Slide 9 text

"What is this magic..?" – Remy, 2002

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

The real hurdle is that there's two parts to real time: client and the server.

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

function main initialize() while message != quit message := get_next_message() process_message(message) end while end function

Slide 14

Slide 14 text

http://tick.rem.io doc.write('console.log("start of the stream...")'); var timer = setInterval(function () { doc.write('console.log("and more...")'); }, 2000);

Slide 15

Slide 15 text

http://tick.rem.io doc.write('console.log("start of the stream...")'); var timer = setInterval(function () { doc.write('console.log("and more...")'); }, 2000);

Slide 16

Slide 16 text

var http = require('http'); var server = http.createServer(function (req, res) { res.writeHead(200, { 'content-type': 'text/html' }); res.write('console.log("start of the stream...")'); var timer = setInterval(function () { if (res.connection.writable) { // keep sending a script with logging res.write('console.log("and more...")'); } else { // else connection has closed, and we can't write anymore // so clear this interval, and *attempt* to end the response clearInterval(timer); res.end(); } }, 2000); }); server.listen(8080); http://tick.rem.io

Slide 17

Slide 17 text

Codified into standards 1. XHR2 2. EventSource 3. WebSockets

Slide 18

Slide 18 text

Codified into standards 1. XHR2 2. EventSource 3. WebSockets

Slide 19

Slide 19 text

Consider only sending required data upstream.

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Mobile over SSL or long polling Authorisation & sessions Scaling client connections: alias CNAME Scaling server: HAProxy, node-proxy, nginx + forwarding & redis backed lookup table Details

Slide 22

Slide 22 text

0314b28f43.example.com 2c46ac0eab.example.com 115885a3ea.example.com Socket server nginx catch all for example.com

Slide 23

Slide 23 text

$ npm install primus emit - named events metroplex - use redis to lookup servers & spark locations omega-supreme - allow broadcasting to server or sparks

Slide 24

Slide 24 text

client client client Server Server primus.metroplex.servers(function (e, serve servers.forEach(function (server) { primus.forward(server, { emit: [type, data] }, noop); }); }); Redis

Slide 25

Slide 25 text

Thanks.