The 'risky bet' that saved Facebook hundreds of millions of dollars

Drew paroski memsql facebookParoskiMemSQL Architect Drew Paroski

Facebook went from 175 million users in February 2009 to 300 million in September that same year.

Most companies wouldn’t consider that a problem. But Facebook was growing so fast, it literally couldn’t order servers and hardware fast enough to handle the demand.

Sure, they could afford it, but they’d have to add so much capacity every day that the equipment wouldn’t arrive in time.

It was a rare problem for Facebook: The kind that can’t be fixed by throwing money at it.

That year, Facebook hired software engineer and computer scientist Drew Paroski, formerly of Microsoft and currently of hot startup MemSQL, to help come up with a solution.

Ones and zeroes

Cyber binary REUTERS/Kacper PempelBinary code, as filtered through popular perception.

To understand what Paroski does, it’s useful to know a little bit about how programming works. You know how in movies and TV shows, a computer program just looks like a bunch of ones and zeroes?

“It’s a gross oversimplification, but it’s basically on point,” Paroski says.

Every single programming language in the world — Java, C++, Facebook’s favoured PHP, and so on — has to be translated into those millions and millions of ones and zeroes such that the computer’s processor can “understand” what the programmer wants it to do.

But that translation into ones and zeroes (what programmers call “machine code”) takes time and energy for any computer. An inefficient or sloppily-written compiler can tie up a computer or a server’s resources, slowing everything down.

Multiply that effect by Facebook’s “very large codebase,” Paroski says, and you start to see why the social network’s data centres were having trouble keeping up with demand.

But if you think about it the other way, Paroski says, there was a big opportunity here: A faster, more efficient software compiler would mean a faster, more efficient Facebook, and none of the programmers who actually work on the website would have to change a thing.

“It’s this great point of leverage,” Paroski says.

Hippity hoppity

Lulea data center 5 - Facebook data centerFacebookA Facebook data center.

When Paroski joined Facebook in 2009, the company had already been attacking the problem with something called HipHop for PHP.

Facebook’s whole website, to this day, is primarily written in PHP — a programming language as popular (for its flexibility) as it is reviled (for its inelegance). HipHop for PHP took Facebook’s PHP code and translated it to C++ code, which was then compiled and ran.

It seems counterintuitive, but C++ is faster to compile than PHP, and so Facebook got back some of its server resources and bought itself a little time. But HipHop for PHP was having “diminishing returns” as far as performance went, Paroski says.

And with Facebook still growing rapidly, the clock was ticking down towards when their servers would once again hit capacity.

“Their data centres are getting slammed 24/7 with web requests,” Paroski says.

Paroski and his small team came up with the idea for a successor to HipHop for PHP. It was called HipHop Virtual Machine, or HHVM, and it would take that PHP code and do the compilation itself.

It was a lot more efficient, and made life easier for developers who didn’t have to worry about PHP code getting lost in translation when it was turned into C++ code.

Risky business

Facebook vp infrastructure jay parikhFacebookFacebook VP of Infrastructure Jay Parikh

It was a “risky bet” for Facebook, Paroski says. HipHop for PHP was a major part of the company’s underlying infrastructure, and there was no guarantee that this new system would actually be any better.

But in 2010, VP of Infrastructure Engineering at Facebook Jay Parikh gave Paroski’s team the go-ahead to start working on it.

In 2012, HipHop Virtual Machine was introduced to the world. At the same time, Facebook introduced Hack, its homegrown programming language that was basically a version of PHP designed to play nicely with HipHop Virtual Machine.

This was a big deal for Facebook. HipHop Virtual Machine meant that Facebook could slow down its spending on data centres and servers, because they could make much better use of what they already had.

In 2013, HipHop Virtual Machine was ready to go into production at Facebook and replace HipHop for PHP. No less than Mark Zuckerberg himself came by to join Paroski’s team for the launch.

“It matters that much to Facebook,” Paroski says.

Today

Eric FrenkielMemSQLMemSQL CEO Eric Frenkiel

In early 2014, Facebook’s Parikh gave a talk where he announced that thanks to its efforts with optimising its computing infrastructure Facebook had saved $US1.2 billion.

Hundreds of millions of dollars of that savings comes from HHVM, and projects like Hack, the Open Compute Project (where Facebook is open sourcing the design of hardware used in its data centres), and other internal weird science projects contribute the balance.

What’s more, Facebook released the code to HipHop Virtual Machine to open source, meaning that any developer in the world can download it and make their own tweaks and upgrades to it. Companies like Box, Wikipedia, and WordPress use HHVM to get their own speed and efficiency boosts.

Earlier this year, Paroski left the company to join a bunch of Facebook alumni at MemSQL, a nerdy-but-hot startup that has investors like Yelp founder Max Levchin, Box CEO Aaron Levie, Google Gmail inventor Paul T. Buchheit, and professional famous person Ashton Kutcher.

MemSQL makes fast, cheap databases that are challenging the likes of Oracle and SAP. It’s a “juicy” challenge for Paroski, who describes himself as “entreprenurial.” Just like at Facebook, he’s specializing in working at the lowest levels of code to make everything work faster.

The eventual goal is for MemSQL to make a product that gives companies access to the kind of fast efficient technology Faceboko and Google use, without their having to follow the Facebook method of making it themselves.

“Most companies are not Facebook or Google,” Paroski says.

NOW WATCH: How to disable all the auto-play videos clogging your Facebook feed

NOW WATCH: Tech Insider videos

Want to read a more in-depth view on the trends influencing Australian business and the global economy? BI / Research is designed to help executives and industry leaders understand the major challenges and opportunities for industry, technology, strategy and the economy in the future. Sign up for free at research.businessinsider.com.au.