Reading: 7 minutes

Could Facebook Be Hosted on AWS?

Facebook is currently a fairly complex technological behemoth. What technological challenges would hosting it on AWS involve?

Header image for article: Could Facebook Be Hosted on AWS?

Since its launch in 2004, Facebook has gone from being hosted on a single server in a room at Harvard to owning seven data centers around the world. Although it seems obvious to us at this point that a company like Facebook would have its own data centers, it is not a far-fetched idea to host a service of this nature on AWS in its early years.

Recently the company Snap closed a deal with Google worth $2 billion, and another with AWS worth $1 billion to host and maintain its platform. Following this news, the folks at SQLizer wondered: what if we hosted Facebook on AWS? Could AWS host such a technological behemoth? How much would it cost annually?

To answer all these questions, they made many assumptions regarding capacity, number of servers, number of users, costs, etc. At no point do they address whether it is viable to host Facebook on AWS, although after seeing the numbers the answer seems fairly obvious.

Servers#

Facebook's data center in Prineville
Facebook's data center in Prineville

Facebook has not shared the exact number of servers it currently has, so we are going to have to make many assumptions starting from old data and extrapolating.

Due to Facebook's size, two questions need to be addressed here: how many servers does Facebook have, and how many does AWS have.

How Many Servers Does Facebook Have?#

In 2012, Data Center Knowledge estimated that Facebook had 180,000 servers. With this estimate, we can calculate the number of servers based on three different data points: users per server, revenue per server, and employees per server.

Users per server

In 2012, Facebook had 1 billion users and 180,000 servers.

  • 1,000,000,000 users / 180,000 servers = 5,556 users / server

In 2017, Facebook was close to 2 billion users.

  • 2,000,000,000 users / 5,556 users per server = 360,000 servers

Taking into account that Facebook has not only doubled its users but also the amount of photos, videos, etc., and that it also hosts Instagram, we double that number: 360,000 * 2 = 720,000 servers.

According to these calculations, Facebook has ~720,000 servers in 2017.

Revenue per server

In 2012, Facebook's revenue was $5.089 billion. If we take this amount and divide it by the number of servers, we get approximately $28,000 per server.

  • 5,089,000,000 / 180,000 servers = $28,272 per server

In 2016, Facebook's revenue was $27.638 billion. Dividing this amount by the $28,000 calculated earlier, we get approximately 978,000 servers.

  • 27,638,000,000 / $28,272 per server = 977,574.98 servers

According to these calculations, Facebook has ~978,000 servers in 2017.

Employees per server

In 2012, Facebook had 4,619 employees, giving us about 40 servers per employee.

  • 180,000 servers / 4,619 employees = 38.96 servers per employee

In 2016, Facebook had 17,048 employees. At 40 servers per employee, that gives us about 682,000 servers.

  • 17,048 employees * 40 servers per employee = 681,920 servers

According to these calculations, Facebook has ~682,000 servers in 2017.

Total

The range between these calculations is 296,000 servers.

  • 978,000 - 682,000 = 296,000

As a final estimate, we take half of this difference added to the larger amount, or subtracted from the smaller amount.

  • 296,000 / 2 = 148,000

  • 682,000 + 148,000 = 830,000 or 978,000 - 148,000 = 830,000

As a final total estimate, Facebook has 830,000 servers in 2017.

How Many Servers Does AWS Have?#

AWS can be divided into:

  • Regions: very large geographic areas, usually continents (Europe, for example), except in cases like "US West".
  • Availability Zones (AZs): smaller areas than regions with several data centers (London, for example).
  • Data centers: server farms, typically between 50,000 and 80,000 servers.

In 2017, AWS has 16 regions and 42 AZs. Taking an average of 65,000 servers per data center, and an average of 1.5 data centers per AZ, we end up with (rounding) approximately 4,100,000 servers.

  • (42 AZ * 1.5 data centers) * 65,000 servers = 4,095,000 servers

As a final total estimate, AWS has approximately 4,100,000 servers in 2017.

Server Capacity

A simple division tells us that AWS has significantly more servers than Facebook would need, so in terms of pure server capacity, AWS would be able to host Facebook without any problem.

Performance#

We cannot assume that AWS servers will provide the same performance to Facebook as its own servers. Facebook has spent billions of dollars improving its own server infrastructure over the years.

The servers found in Facebook's data centers are optimized down to the last detail for maximum performance and efficiency. From the architectural design of the data center itself, to the chassis of each server, everything is of Facebook's own design and creation.

Facebook has its servers optimized to run Facebook. For example, they have a section called "cold storage" in their server farms where they store photos and videos that are no longer viewed (for example, photos uploaded to the network several years ago). This storage is only powered up when someone accesses that content, so its state depends on demand. In contrast, and although AWS also creates its own hardware, AWS is designed for a more generic purpose.

So assuming that if Facebook were hosted on AWS it would need extra servers (since they are not fine-tuned to Facebook), we can estimate that Facebook would need 10% more capacity than it would have on its own servers. This would give us that Facebook would need 913,000 servers on AWS to obtain similar performance (830,000 servers * 1.1 = 913,000 servers).

Software#

Facebook has developed over the years a set of technologies based on existing open-source technology adapted to its business needs. From HipHop Virtual Machine (HHVM) as a virtual machine for its PHP code to its own adaptations of the MySQL engine, Facebook uses various technologies (some adaptations, others of its own development), so it could be thought that not all of them would be 100% compatible with AWS. Just as happened with Netflix, Facebook would most likely need to adapt a large part of its code to AWS resources.

Costs#

The million-dollar question: how much would it cost to host Facebook on AWS? Here the assumptions are even greater, as it is practically impossible to know exactly due to not knowing which technologies from the entire AWS stack would be needed, to what extent, and what monthly data transfer is handled.

To calculate these costs, we will continue to assume that Facebook has 913,000 servers divided across different AWS services, such as EC2, S3, RDS, photo and video storage and transfer, a combination that would give us approximately 1,265.5 Petabytes of monthly data (1,256,000 Terabytes). This assumes:

  • 300 million photos uploaded each day, at an average of 4 MB per photo.
  • 100 hours of video uploaded at an average of 200 MB per video.

The calculations can be seen at this link using the AWS calculator, and among the many assumptions we can find:

  • 713,000 EC2 instances of type r3.2xlarge
  • 1,256.5 Petabytes of storage in S3
  • 200,000 RDS instances of type db.r3.2xlarge in Multi AZ with 1TB of space.

The result is staggering: $5.97 billion annually.

Conclusion#

The answer to the question Could Facebook be hosted on AWS? is a resounding yes, although the real challenge is not the cost, but the software. Facebook's entire tech stack is prepared to work perfectly on its own servers (which are also fine-tuned to the last detail), so a migration of this magnitude would take YEARS (it took Netflix eight years to migrate to AWS).

Therefore, the best thing they can do is leave everything as it is. After all, they had already spent nearly $4 billion in 2012 on their server infrastructure, which today could easily be triple that.