0

I'm working on a project, and I'm trying to decide whether to use WebSockets or longpolling.

This brings up an interesting question: what is the breakeven point between using WebSockets instead of traditional HTTP techniques? Clearly, if you need daily updates, http requests are better, but for real-time updates, WebSockets would be better. (I think. Correct me if I'm wrong!)

Let me be more specific:
Assume that for a good user experience a web app requires a user to be updated in a period of time P.

Additionally, assume that we are only using WebSockets to send updates from the server to the client, and that the average JSON object sent looks like this ( I'm including this because I imagine average data size matters):

{ 'animal' : 'dog',
  'people_who_have_petted'  : ['Foo', 'Bar', 'Thomas'], 
  'people_who_like' : ['Tom', 'Foo', 'Bar', 'Thomas','John', 'Mary'], 
  'people_who_dislike' : ['Jerry','Cat', 'Banker'] 
  'user_voted_phrase' : "Dogs are a man's best friend!"
}


In your experience, at around (no need to be extremely precise) what period P would it make more sense to use WebSockets instead of traditional http techniques for scaling and cost purposes?

Luigi
  • 4,129
  • 6
  • 37
  • 57
  • I'd suggest you read this post which discussed when ajax is preferred and when websocket is preferred: http://stackoverflow.com/questions/28204720/mojolicious-should-i-use-one-websocket-or-several/28206740#28206740 – jfriend00 Apr 10 '15 at 00:10

1 Answers1

0

The right decision depends on lot of factors, not only the refresh intervals.

Hard downsides of long polling?

WebSocket/REST: Client connections?

On my experience, I would not use long polling unless there is a big reason or just the data push feature of my application is very dull.

Community
  • 1
  • 1
vtortola
  • 34,709
  • 29
  • 161
  • 263
  • Thanks! Your answer in the second link really answered my question. For my purposes, I think I'll use a mix of REST and web sockets like you describe. – palindromicPrimes Apr 09 '15 at 22:49