Search code examples
ruby-on-railsreal-timemessagingpubnub

Rails + Pubnub Integration Architecture


I am new to Pubnub and real-time application. I wrote some ruby application before and I am currently research an option to integrate pubnub into my rails application. I read pubnub docs already and have an basic architecture in my head but not quite sure if it is good or even feasible. I appreciate any opinions.

In the application, there will be a peer to peer chat window, and one person can talk to any person he wants.

1) Rails will not store any messages, and it will only stores which channels each person is subscribing to. In this case, since it is a peer-to-peer chat, a channel person publishing to is also the channel the person subscribing to. Rails will store all channels informations for all channels. And thats' it.

2) In client side, server will give each current_user the channels him/her subscribing/publishing to and using those channels, current_user can retrieve all history chats from pubnub server for channels he/she subscribes to.

This is what's in my head. Is there a better architecture implementation ? As far as I read in pubnub docs, they don't store channels for each unique user. Also, in terms of security, since everything will happen in the front-end and subscribe/publish key will be exposed to the browser. How secure is it ? Any drawbacks to this implementation ?

Thanks !!


Solution

  • Its very feasible... you can even get more creative after you nail down the basics. Here is a good chat with PubNub overview link:

    http://www.pubnub.com/use-cases/chat/

    Here you will find links to iOS and JS demo chat implementations.

    Just for our Ruby fanatics, here is the link to a chat app purely using our Ruby SDK:

    https://github.com/pubnub/ruby/blob/master/examples/translator.rb

    The ruby app is pretty cool, as it lets people not only chat, but chat across multiple languages (via Bing translation API).

    I'd say cut your teeth on these, and if you need further guidance, just shoot an email to [email protected], and we'll get you up and running with more tools and tricks specific to your use case.