Sunil Kumar Jha
Sunil Kumar Jha

Reputation: 881

How does Facebook real time works?

I don't know how to formally state this question as i don't know what is actually happening here. Whenever any user comments on my post, facebook makes a request like below to display that comment without me doing anything.How do they do it?

https://0-edge-chat.facebook.com/pull?channel=p_100009456028304

This cannot be push notification as they are are making a pull request constantly(i checked using developer tools available in browsers, although i am not sure about if it is push notification or not).They are constantly making a pull request to above URL.What this technology is called? Constant request Can someone please help me understand this. Maybe this question is duplicate and already answered on stack overflow.But as i don't what this is, it's hard to search.(i tried but couldn't find anything)

Upvotes: 6

Views: 3739

Answers (1)

Alessandro Alinone
Alessandro Alinone

Reputation: 5174

As correctly said in the comments, this is called Long Polling. In a nutshell, there exist 5 ways to implement real-time updates in a web page:

  1. Web Push
  2. WebSockets
  3. HTTP Streaming
  4. HTTP Long Polling
  5. HTTP Polling

Facebook is using Long Polling, with a poll timeout of 50 seconds. This means that an HTTP request is done by the browser to the server. If no updates are available, the request is kept pending by the server for a maximum of 50 seconds. This way, as soon as an update is available, it can be pushed to the client without waiting for a new client request (as in normal polling).

Upvotes: 5

Related Questions