I am building a social application and was wondering how facebook achieve their notifications.
As you know, facebooks notifications are instant. As soon as someone takes an action, people are notified. 

I assume they don't have a query running on the database all the time.

Can someone point me in the right direction. Thanks