Behind the Facebook Desktop Notification

Me and a friend looked at what the newly released Facebook Desktop Notification is doing (a simple OS X application which gives you seemingly real-time visual notifications when something happens on Facebook). Since it's very quick at displaying notifications and since people have requested a pub/sub API to Facebook for quite some time, we thought that hey, maybe they're trying out a new notify-API! Let's reverse engineer it..

Well, turns out they are actually polling every 30 seconds. Wow. With 100m+ users, thats a lot of queries.

The application uses fql.multiquery to send optimised queries and also asks for JSON responses in order to keep the bandwidth usage down.

SELECT thread_id, subject, snippet_author, snippet, unread, updated_time 
 FROM thread 
  WHERE folder_id = 0 AND updated_time > 1253102646

The response looks like this, if something new has happened since last time we checked:

   "snippet":"igen, hej hej! :)",
   {"name":"Rasmus Andersson",
   {"name":"Jon \u00c5slund",

In other words; they return the minimum amount of data in a single response needed to represent the event — subject, time, message excerpt and the parties involved in the discussion.

Well, most if this is fairly old news, but the fact that themselves (Facebook) release an application which polls the API at such a high rate indicates that we (merely mortals) can do so too. Opens up for close-to-realtime applications.