I am developing a rails app that allows users to post, much like facebook or stackoverflow. I want to implement an alert system that lets a user know when a new post has been added (just like here at stackoverflow).
Now, I am going to be deploying to heroku. This poses some problems, such as the fact that heroku does not support websockets. If I want websocket support, I am going to have to pay for them via Pusher or Pubnub – expensive services. However, I am not so sure that I need that kind of setup. I might be able to get away with long polling (via an ajax request every so often with a self calling setTimeout).
My question is, at what point do I need to use a push service such as Pubnub/Pusher over just an ajax interval call? Or better yet, how can I get away with an ajax interval call (calling every 30 seconds or minute maybe)? (Is it smarter to just use ajax in the begging anyway, then upgrade to a service if I get flooded with traffic?)
My updates do not need to be real time necessarily, but I would like it as soon as possible.
By using a service like Heroku it means you are offloading the pain of the web hosting environment. It means that as your service gets popular it will handle the scaling for you. If you use any form of polling you will need to scale the Heroku part of your service sooner as more resources are used up by the polling requests.
Polling can be much less efficient but it really depends on how frequently your users will see updates. If updates are reasonably frequent, so the polling request do actually return data, and realtime doesn’t really matter, then polling might be an acceptable solution. But it does mean notifications won’t be instant.
Whether you should use a hosted service for the realtime infrastructure part of your app really depends on:
Since I work for Pusher I obviously believe that the benefits of offloading your realtime infrastructure to a WebSocket-focused service are high. The benefits of a strong community, good development tooling and docs should also be taken into account when weighing up pros and cons. If cost is a problem then I know Pusher support is a good place to get in touch and ask about potential discounts/deals.