Implementing Notifications in Rails Implementing Notifications in Rails ruby-on-rails ruby-on-rails

Implementing Notifications in Rails


Facebook and Twitter are not mid-size Rails applications. They are companies. The tech that runs them is distributed and mostly custom, especially in the case of Facebook.

The part that you seem to be grasping for is how they determine who to notify in a performant and scalable way. This is where shit gets real. You can find a lot of information about the architecture behind each on of them, and there is certainly a lot of great stuff to help you think about these things, but ultimately none of it is going to be something you implement into whatever application you're building.

http://www.quora.com/What-is-Facebooks-architecture

Facebook Architecture

http://www.infoq.com/news/2009/06/Twitter-Architecture

http://engineering.twitter.com/2010/10/twitters-new-search-architecture.html

Plenty more juicy details over at Quora.


Unfortunately, none of this gets you closer to your goal. I think the most realistic thing for you to do to start out with woud be to simply tie in a service like Pusher to send messages to clients without worrying about it, use an ActiveRecord Observer to add notifications to a background queue where the workers actually send those notifications to Pusher. This is a day or less of work and it should scale well to at least 10k notifications a day. Once you start having performance problems, ditch the Observer and Pusher for something like Goliath that can handle both of the jobs locally.

Bottom line, learn what you can about large and experienced systems that have been put through the paces, but mainly just to see what problems they ran into and how they solved them. These methods aren't the same among the big guys even, and they are going to vary for each implementation.

Hopefully that helps point you in a good direction. :)


You can use ActiveRecord callbacks while record is saved (like before_save, after_save or before_create, after_create) to go through comment content, find and create all mentions models and save them to db.


I actually am interested in a concrete answer to this myself. I don't know how Facebook and Twitter do it, but I do know from general searches that the gem acts-as-taggable-on could get the job done. Check out https://github.com/mbleigh/acts-as-taggable-on.

Also, this question on stackoverflow might also provide you with some info: Implementing twitter-like hashtag on rails

Good luck. I encourage you to try to get more attention to this question and get a more solid answer than what I've said. :]