By querying some sort of API in the background.
Often it's just a matter of making a request to an appropriate REST endpoint (having the required credentials such as an API key/secret, for instance). Example: Twitter API docs.
For faster, real-time updates one can keep a channel open and let the server push updates over it.
This can be done with a long-lived HTTP connection just waiting until the next piece of data. Example: Twitter Streaming API for real-time updates.
WebSockets technology is a good idea for that, too. Example: Stack Overflow notifications (could not find documentation, sorry, but here's a client implementation).
See also this discussion, and this Wikipedia entry.