The new technology is already powering the entire site

Jun 11, 2013 09:20 GMT  ·  By

Facebook has completely changed the underlying infrastructure powering the service several times now, and you haven't even noticed. That's actually a sign that Facebook is doing a great job at it.

A site the size of Facebook has to rely completely on its own tools and technology. This means great flexibility but also great risks.

On the one hand, a completely custom solution may be significantly more efficient than off-the-shelf software. On the other, it may not even work properly.

A small team of experienced engineers spent the past couple of years revamping the software infrastructure that powers the site.

Facebook is now a decade old. When it all started, Mark Zuckerberg used the tools at his disposal, the standard web developer's tools at the time, to build the site. Which means yes, Facebook was built in PHP.

And now, a decade later, much of the site is still coded in PHP, a language that has long fallen out of fashion among the tech elite, particularly for a site this large.

PHP's advantage was that it was fast to work with and plenty of developers are familiar with it. Its big disadvantage is that it's slow, at least when used to power sites like Facebook.

Rather than just add more and more servers, which would have been unfeasible at some point, Facebook decided to speed up the code without ditching PHP.

This resulted in HipHop, a tool that translates PHP code into C++, which can then be compiled and run significantly faster on the servers. This was back in 2010.

The tool provided a huge performance boost, but there were some who believed they could do even better.

They reckoned that they could build a PHP virtual machine which would run PHP code incredibly fast without having to convert it to C++ and compile it to native code.

Facebook unveiled its PHP virtual machine in late 2011. But it only became fast enough to use on the main site a few months ago.

With a PHP virtual machine, PHP code is compiled as it is run (just-in-time compiling), meaning there's no time spent converting it to C and compiling it beforehand.

Compiling it on the fly is inherently slower than just running already compiled code. But as modern JavaScript engines – all of which use JIT compiling – have shown, you can get pretty close to native code speeds with these methods.

The upside is that you can continue to write PHP code and not worry about it being slow. In fact, at this point, the PHP virtual machine that Facebook has built, which is dubbed the HipHop Virtual Machine, despite having no connection to the previous tool, is faster than HipHop.

And it's already in use on the site. Wired has details on how the small Facebook team was able to achieve so much in so little time.