Realtime with Rails?

Hi All, I’m planning an activity stream feature for an existing product (something similar to Facebook’s notification icon + notification dropdown. The goal is to have the server be able to push messages to specific users such as incrementing a count on-screen or pop up a grow-like notification with some info.

My main concern is scalability and the ability to handle hundreds or thousands of concurrent users. I’ve built this before with pusher, but this time around, my customers are mostly large enterprises, so I’m avoiding companies like Pusher or RabbitMQ so as to not have another vendor/company handling data related to customers.

I’ve found a couple gems that look like they add real-time functionality to Rails - but this seems like it is not scalable
Rails4 ActionController::Live - seems too immature to use from what I’ve ready.

Any ideas on the best, most scalable approach?

Thanks in advance

1 Like

Isn’t there something called event-emitter?

I’m also interested in pushing messages from rails to a web client. I’ve used the MessageBus gem for this and it works very well but I haven’t tried it on a busy app yet. I’d be interested to hear from anyone who has used something like MessageBus on a system with many concurrent users.

Maybe check out ActionCable?

This does not answer your question but maybe it comes handy for someone else reading this post and evaluating SaaS solutions. I’ve heard good things about Firebase.

Maybe Faye could be something worth looking into or as @maclover7 suggested have a look at Rails 5 ActionCable.

@austinwang, this might depend a little bit on your server infrastructure, but having built these kinds of activity feed APIs before, I think there’s considerable value in using a service like Pusher or PubNub to feed these kinds of activity streams if you are very concerned about scale and load. They specialize in this kind of use case, and they have purpose-built infrastructure to handle it. Through their focus, these providers have already dealt with all sorts of complicated edge cases and pain points.

If you’re worried about privacy, it might be possible to trim down whatever ends up in the activity feed messages so that the user knows there’s something to look at, but that sensitive information does not pass through someone else’s infrastructure.

One thing you could do to make it easier to switch would be to build an adapter around your vendor’s library, making it less complicated to swap that out for a competitor (or a later internally-built) solution. The adapter would specify your own API for broadcasting and receiving messages, and any vendor-specific code you interact with would just mate that vendor’s API up with your adapter.

1 Like

Thanks for the suggestions everyone.
I ruled out ActionCable as it is still too new IMO to be used without a decent amount of work testing in prod (and upgrading to rails 5).
Pusher , I had ruled out because of the 3rd party dependency, but I do like the @geoffharcourt’s idea of writing a wrapper and having the option to swap it out any time.

So far what I’ve ended up doing is setting up a separate node based app on heroku. Both my original Rails app and the new Node one are hooked up to the same Redis service (Heroku redis). Whenever notifications come up on Rails, I do a Redis publish which the node server receives and pushes out to clients.

1 Like

Funny thing is that you are using Message Bus right now as you browse this very forum :slight_smile: It is the engine that drives Discourse live notifications deployed on thousands of sites across world. We serve millions of requests to the message bus a day.

Recently we added a Postgres backend as well.

1 Like