Want to stay on top? Ruby Weekly is a once-weekly e-mail newsletter covering the latest Ruby and Rails news.
     Feed Icon

Pusher: WebSocket-powered Realtime Browser Push Service for Rubyists

By Peter Cooper / May 7, 2010

Pusher is a new Web service from New Bamboo that makes it easy to push data to users of your web applications "live", outside of the request response cycle. They've embraced Web Sockets technology and built a REST API to which you can post events. Its flexible channels are based on a publish/subscribe model and you can send events as JSON which communicate with all connected browsers.

Websockets are part of the specification for HTML5, and are essentially long-running native TCP connections in the browser. These allow a client to establish a connection to a server, and have immediate feedback when there are events they need to be notified of. Websockets make your applications more dynamic, and break them out of the traditional stateless request-response cycle. Your applications can therefore rely on maintained state in the browser which will be kept fresh with messages from your server.

Pusher makes adding Websockets to your application a quick and easy process. Pusher provides a simple Ruby gem) for interacting with its REST API, which includes authentication. There's lots of documentation on the site, along with some more in-depth tutorials. Pusher also provides simple tools for debugging the socket connections to your application. Their event-based abstraction is handled in a Javascript library which also includes support for a flash fallback option.

Or.. try the DIY approach

The tools for creating a similar systems yourself are widely available, and it's pretty easy. Ilya Grigorik recently put together a walkthrough of creating a simple Web Sockets server in Ruby using EventMachine. There are plenty of other open source solutions for message pushing generally like Juggernaut and Cramp.

In many cases running your own standalone socket server gives you a lot of flexibility for more bespoke deployments. However, maintaining these socket servers, debugging the various issues that come up, and keeping up with the specs is not something everyone wants to be doing. Given the popularity of utility-based hosting providers such as Heroku, Pusher is an interesting option for a de-coupled socket service you can use to keep your infrastructure lean.

Disclaimer: New Bamboo is a sponsor of Ruby Inside for their Panda service. I only noticed this had happened after working on this post (!) but a disclaimer is required nonetheless ;-)

Comments

  1. Ilya Grigorik says:

    Great writeup Peter. As far as I'm aware, Pusher is actually powered by em-websocket under the hood! Also, someone recently contributed the flash fallback example into the repo as well, so it's all there for the taking!

  2. Sohan says:

    The Drink Rails blog linked to your post as one of the top ruby on rails blogs of the day.

Other Posts to Enjoy

Twitter Mentions