Search code examples
ajaxruby-on-rails-3chatfaye

Why use Faye for chat and not use Ajax (rails)


I am not sure what are the advantages for using Faye or some other push system and not use Ajax for it.

Specifically I mean for implementing chat and notification functionality.

If I make a chat message model, and in my post ( which has many chat messages) , in the post page I can use Ajax to refresh the messages and I get the chat functionality.

Am I missing something on Faye or with Ajax? Is it more efficient?


Solution

  • Faye is establishing a connection that the server can push data to the client with. With Ajax the client must request data and if it doesn't know that new data is available (which is the case in a chat client) then it must poll periodically for new content.

    Is it more efficient? If the chat system sees enough traffic that your poll period is getting new data every time, probably not. If, on the other hand, you have an idle chat room then all of that polling is going to be chewing up resources that could be avoided by having the server push the data.

    The flip side of this is that you are keeping a connection open with the server. This could work against you if you have a large number of idle clients. Because of this, it would be context sensitive as to which approach is better, or perhaps even a hybrid approach (opening a Faye connection for active use and then idling out to Ajax polling on an infrequent basis).