This impressive and beautiful stuff is asynchronous calls made from the client to the server using Ajax.
A very simple approach is to use jQuery Ajax to make an asynchronous call inside a setInterval to search for "updates" of a question (this is the question with ID 17779628. We can see on the URL =P). So, the call to the server can pass this ID and a TimeStamp (a date) of the last call made to the server. The server then brings updates that occurred from TimeStamp to DateTime.Now
.
I am not sure about the real implementation of Stack Overflow, but I already did a lot of stuff just like this.
Another tip:
There is an improvement. ;)
Modern browsers contains implementations of WebSocket. Since sockets are "peer-to-peer" and not "client-server", modern browsers don't need the approach with setInterval. Instead, you can implement a WebSocket opening in JavaScript and then the server can send the updates actively in the moment that it happens (you can use design patterns that include events).
Take a look at CanIUse to see which browsers supports WebSocket.
EDIT
Anyway, I just opened the code for you. The Stack Overflow's JavaScript code uses a singleton design pattern for the JavaScript code. Just take a look at the StackExchange
variable in your browser console. That is the heart of the JavaScript code here. As you can see, there is a whole API built upon this StackExchange
variable. Now, search for StackExchange.realtime.init('sockets.ny.stackexchange.com:80');

Then, take a look at the implementation of StackExchange.realtime.init
at your console. It seems that they support asynchronous updates with WebSocket. This is nice and modern, but only supported by new browser versions. If you need to maintain backward compatibility, you can support both WebSocket (for new) and an Ajax implementation (for old browsers).
