• by Boz on Wednesday, September 26, 2007 at 12:00pm

      The PHP programming language has solidified itself as the language of choice for many top internet properties, including Facebook. PHP is easy to use and integrates well with Apache, Memcache, and MySQL. Despite its suitability for web development and scripting, PHP is generally not the best choice for standalone software or servers. C++, on the other hand, is well suited for building both online and offline services.

      Unfortunately, if the new services operates with data managed by the existing PHP code base it can be dangerous to use a... separate data access pattern. If the cache keys or database schema were to change in the PHP code base then the service would be broken (and potentially corrupting data for the PHP code base) until the code was updated and the program recompiled and restarted.

      Faced with this problem we decided to embed the PHP Interpreter into C++ binaries. This isn't a novel endeavor by any means; Apache uses the PHP Server API (SAPI) to accomplish exactly that. However, when we began attempting integration of our own we found that the SAPI required quite a bit of expertise to manipulate effectively.

      In order to make embedding PHP truly simple for all of our developers we developed the PHPEmbed library which is just a more accessible and simplified API built on top of the PHP SAPI. The library is so useful, we decided to share it with the world. Check it out for yourself at http://developers.facebook.com/phpembed/



      Boz is a software engineer at Facebook and, like PHPEmbed, he is open source

      See More
    • · Comment · Share
    • by Boz on Thursday, February 15, 2007 at 4:36pm

      News Feed may not walk around downtown Palo Alto on awesome hydraulic legs handing out customized stories to people on the street (yet) but it _is_ a robot. While we sleep it stays up sifting through the enormous volumes of information about our friends on Facebook and picks just the best pieces to show us. While we eat it is keeping track of whom we seem to be keeping an eye on recently as well as remembering whom we have cared about in the past. It is very discreet and never talks about this secret information to other people or systems, it... just needs the information to do a better job picking stories because it thrives on people finding its stories useful and entertaining.

      Let's walk through what News Feed does when it is publishing stories for me. First, it gets a list of all my friends and acquaintances on Facebook and considers how often I interact with them. Then, with full respect for all privacy settings, it gets a list of all the things my friends have done on the site since it last checked. It also looks up all the stories it could have published the previous week in case one of them needs to be updated. After looking at all that information and considering my News Feed Preferences, it picks just the few stories that are good enough for publication and puts the rest in a safe place until it gets back to me again. It does all of this for me in 0.00023 seconds.

      That may not sound impressive at first, but let's look at more numbers. It takes less than an hour for News Feed to publish stories for every user on Facebook. With 17 million users on Facebook there are over 2 billion friend connections and over 5 billion actions taken every hour. That means News Feed is processing 1.4 million new user actions and 12 million previously unpublished stories every second to find just the best 13,000 stories to give our users or the top 0.1% of all possible stories.

      News Feed is also growing faster and smarter all the time. It has gone from processing an average of 100 MB of data each second when we launched to over 300 MB/s now (that's like listening to 100 mp3s a second!). In fact, News Feed has been so successful it has even been getting involved with real estate; it started out in a 19 server apartment, has now signed the lease on a 109 machine house in the suburbs, and already has plans for expansion.

      When we built News Feed, we thought we were building a pretty cool and innovative customized news aggregator. It turned out we built a friend who knows us so well it can show us stories we didn't even know we wanted to see. Stay tuned to your Home pages (and here in the blog) for improvements as new stories begin to bring together more data and we build systems to let News Feed get an even better idea what kind of stories you like.


      Boz is a software engineer at Facebook. He doesn't anthropomorphize everything, just News Feed. Which is a robot.

      See More
    • · Comment · Share

Most Popular Stories

Newsroom

Newsroom

Visit the newsroom for the latest updates from Facebook.

Facebook Favorites

Blog Archive

Looking for a specific post? Visit our full archive of blog posts sorted by categories and dates.