A normal web application works as follows: a browser sends a request to a website. The site’s server receives the request, tracks down the requested file, process the request and sends a response to the browser. In traditional web servers, such as Apache, each request causes the server to create a new system process to handle that request.

There was another improvement came in the form of Ajax. Instead of requesting a whole new page each time, we’d only request the piece of information we actually wanted.

But consider the case of social networking sites, where each user’s feed is updating in real time. The only way that’s possible is if each user has an active connection to the server at all times. The simplest way to do that at present is through long polling.

Long polling essentially tricks HTTP into acting like a persistent connection: as soon as the page loads, it fires off an Ajax request to the server, even if the page doesn’t want anything in particular. But, unlike a normal Ajax request, the server doesn’t respond right away. It just waits, and fires back a response only when it has something new it wants the browser to display. For example, as soon as one of your friends adds a new post, the server returns the response telling the browser to update its display. As soon as the browser receives the response, it shoots back another request. This way the browser is always waiting for a new event to happen on the server side.

Read More