Pusher.com for real-time client updates

Pusher.com is a service that applications can use to send real-time updates to web clients to have things update automatically. And it’s awesome. Here’s why:

  1. It’s easy to implement on the server side
  2. It’s easy to implement on the client side
  3. It scales your application for you

What would you use it for? Creating instantly updating chat clients. Showing activity on a map as it happens. Showing when people sign in or out of a service. Interactive games. Live dashboards.

You can just play around for as long as you need with the free sandbox plan.

Implement it on the server side (Ruby on Rails):

gem 'pusher' # add to Gemfile
Pusher['test_channel'].trigger('my_event', 'my data string')

Implement it on the client side:

<script src="http://js.pusherapp.com/1.8/pusher.min.js" type="text/javascript"></script>
<script type="text/javascript">
  var key = ''; // Found in your Pusher sandbox account
  var pusher = new Pusher(key);
  var channel = pusher.subscribe('test_channel');
  channel.bind('my_event', function(data) {

Invoking the Pusher code from the server side will now show a Javascript alert on all clients that have a page open with the above Javascript on it.

Pusher’s technology is based on HTML5 WebSockets. There are obviously other WebSockets based libraries and services but there is a distinct advantage to Pusher’s implementation. First of all, Pusher implements a fall-back using Flash. The combination of these two technologies means it will work on pretty much any browser. Pusher also has a great debugging tool which lets you see who is listening and what data is sent on the channel.

Whether you have 5 users listening on the channel or 5,000 it does not matter. You only write to the channel once and any client listing will receive the event. All you need to do is pay Pusher some more money as your application gains more users, but hopefully it means lots of users are using your application.

So as you can see, Pusher is pretty awesome, because it will make your application more awesome! I’m excited say that today’s BugHerd release makes use of it to push task updates to other users in the project.

Leave a Reply

Your email address will not be published. Required fields are marked *