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

PubSub at Rails

PubSub at Rails

Action Cable is a Rails component that helps to incorporate real-time features into your Rails application. We will talk about how Action Cable implements PubSub using WebSocket protocol, whether WebSocket protocol is always a good choice, and what are alternatives to it.

Sergey Nartimov

November 10, 2016
Tweet

More Decks by Sergey Nartimov

Other Decks in Programming

Transcript

  1. Action Cable Action Cable seamlessly integrates WebSockets with the rest

    of your Rails application. http://guides.rubyonrails.org/ action_cable_overview.html
  2. WebSocket protocol var socket = new WebSocket('ws://www.example.com/socketserver') socket.onopen = function

    () { websocket.send('Hello') } socket.onmessage = function (msg) { console.log(msg) }
  3. Action Cable Action Cable uses Pub/Sub to communicate between the

    server and many clients. http://guides.rubyonrails.org/ action_cable_overview.html
  4. Message reliability Messaging reliability is far more important than WebSockets.

    WebSockets are an implementation detail, not a feature. Sam Saffron https://samsaffron.com/archive/2015/12/29/ websockets-caution-required
  5. Message reliability Twitter use HTTP/2 + polling, Facebook and Gmail

    use Long Polling. Sam Saffron https://samsaffron.com/archive/2015/12/29/ websockets-caution-required
  6. HTTP/2 There is no websockets for HTTP/2. By this, I

    mean that there’s no way to negotiate or upgrade a connection to websockets over HTTP/2 like there is for HTTP/1.1 as expressed by RFC 6455. Daniel Stenberg https://daniel.haxx.se/blog/2016/06/15/no- websockets-over-http2/
  7. HTTP/2 Open 20 tabs with a WebSocket based application and

    you are risking 20 connections unless the client/server mitigates. Sam Saffron https://samsaffron.com/archive/2015/12/29/ websockets-caution-required
  8. HTTP/2 HTTP comes with a lot of goodies, and by

    moving away from HTTP we'll lose it all. Caching, routing, multiplexing, gzipping and lot more. You could reimplement all of these things in Action Cable, but why? Nate Berkopec https://www.nateberkopec.com/2015/09/30/action- cable.html
  9. message_bus A reliable, robust messaging bus for Ruby processes and

    web clients. https://github.com/SamSaffron/message_bus