Muddling my way through real time

C8b387c489181844b3ffc704fadc0f14?s=47 Remy Sharp
September 23, 2014

Muddling my way through real time

If your business deals with data on the web, then that data must be handled in real time, otherwise you're doing your user a disservice.

C8b387c489181844b3ffc704fadc0f14?s=128

Remy Sharp

September 23, 2014
Tweet

Transcript

  1. None
  2. http://game.rem.io

  3. Real time is easy, cheap, and expected.

  4. Fast Self-updating

  5. Instant Self-updating

  6. None
  7. function updatePrices() { $.get('/prices?stock=MSFT', function (data) { renderPrices(data); setTimeout(updatePrices, 60

    * 1000); }); }
  8. The server is the ultimate source of truth. We want

    the server to push the prices to the client.
  9. "What is this magic..?" – Remy, 2002

  10. None
  11. The real hurdle is that there's two parts to real

    time: client and the server.
  12. None
  13. function main initialize() while message != quit message := get_next_message()

    process_message(message) end while end function
  14. http://tick.rem.io doc.write('<script>console.log("start of the stream...")</script>'); var timer = setInterval(function ()

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

    { doc.write('<script>console.log("and more...")</script>'); }, 2000);
  16. var http = require('http'); var server = http.createServer(function (req, res)

    { res.writeHead(200, { 'content-type': 'text/html' }); res.write('<script>console.log("start of the stream...")</script>'); var timer = setInterval(function () { if (res.connection.writable) { // keep sending a script with logging res.write('<script>console.log("and more...")</script>'); } 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
  17. Codified into standards 1. XHR2 2. EventSource 3. WebSockets

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

  19. Consider only sending required data upstream.

  20. None
  21. 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
  22. 0314b28f43.example.com 2c46ac0eab.example.com 115885a3ea.example.com Socket server nginx catch all for example.com

  23. $ npm install primus emit - named events metroplex -

    use redis to lookup servers & spark locations omega-supreme - allow broadcasting to server or sparks
  24. client client client Server Server primus.metroplex.servers(function (e, serve servers.forEach(function (server)

    { primus.forward(server, { emit: [type, data] }, noop); }); }); Redis
  25. Thanks.