Feb 8, 2011 11:35 GMT  ·  By

Facebook quietly rolled out real-time comments a couple of weeks ago. At the time, users noticed that new comments on status updates, photos, videos and so on started coming in as soon as they were posted and without updating or reloading the page. Facebook has now confirmed the feature and explained the technology behind it.

As you can expect, creating a real-time commenting system for a site with 600 million people is no easy task.

Millions of people are visiting Facebook at any given time and many of them have something to say, either replying to their friends or adding their two cents.

"Commenting on Facebook content has been an asynchronous form of communication. Until now. Live commenting, which we rolled out to all of our users a couple weeks ago, creates opportunities for spontaneous online conversations to take place in real time," Facebook's Ken Deeter wrote.

For the comments to flow and reach their destination, the ones viewing a certain page, in near real time - it can't be instantaneous of course - the web page has to be in constant contact with the data centers.

But 'asking' (poling) to see if something has updated at a fast enough rate would put a huge strain on Facebook's servers. Instead, Facebook took the opposite approach by pushing updates to the ones that need them.

"At Facebook, traditionally, writes are applied to one database and asynchronously replicated to databases across all regions. This makes sense as the write rate is normally much lower than the read rate," Deeter explained.

"Because of our unique situation, we settled on the completely opposite approach: 'write locally, read globally.' This meant deploying distributed storage tiers that only handled writes locally, then less frequently collecting information from across all of our data centers to produce the final result," he explained how the live commenting system works.

The system keeps track of who is watching what on Facebook. This information is stored 'locally,' i.e. at the data centers closest the person viewing, the one where they get their data.

When someone writes a comment, Facebook checks to see who is viewing the pages where the comment will show up, by checking all of the locally stored data and then sends out the update.