Skip to Content

What technology is Facebook built on?

What technology is Facebook built on?

Facebook is built using a variety of technologies, both proprietary and open source. At its core, Facebook is powered by PHP, MySQL, React, GraphQL, and other tools. Some of the key technologies that make up Facebook’s tech stack include:

Frontend

– React – A JavaScript library for building user interfaces. React allows Facebook to build complex, interactive UIs that can update efficiently.

– Relay – A JavaScript framework for building data-driven React applications. Relay fetches data from Facebook’s GraphQL APIs.

– Flow – A static type checker for JavaScript code, which helps catch bugs early.

– Jest – A JavaScript testing framework used by Facebook for testing React components.

Backend

– PHP – A widely-used scripting language that runs Facebook’s backend code.

– Hack – A programming language built by Facebook that interoperates with PHP. Hack allows Facebook to write fast, type-safe code.

– HHVM – The HipHop Virtual Machine developed by Facebook that serves as a runtime for executing Hack and PHP code. HHVM achieves greater speeds compared to traditional PHP environments.

– MySQL – An open source relational database that Facebook uses to store its operational data across its services.

– Memcached – A distributed memory caching system used by Facebook to cache data and reduce load on databases.

Infrastructure

– Apache Thrift – A framework for scalable cross-language RPC between Facebook’s services.

– Haystack – Facebook’s object storage system for photos and other binary data.

– TAO – An automation platform for managing Facebook’s compute infrastructure. TAO handles deployment, monitoring, and maintenance.

– Backbone – An internal 100Gbps Ethernet network that connects Facebook’s data centers.

Frontend Stack

Facebook’s frontend stack is responsible for rendering the user interface that gets delivered to billions of people across web and mobile apps. Let’s explore some of the key frontend technologies:

React

React is the primary JavaScript framework used by Facebook to build its web and mobile apps. Here are some key facts about React:

– Created internally by Facebook in 2011 and open sourced in 2015.

– Allows building modular, declarative UIs using components.

– Implements a virtual DOM diffing algorithm for fast, efficient updates.

– Enables server-side rendering for improved initial load performance.

– Integrates with other libraries like React Router for routing and Redux for state management.

React has become highly popular outside Facebook as well, and is now one of the most widely used frontend libraries.

Relay

Relay is the homegrown JavaScript framework created by Facebook for fetching and managing data in React applications. Key facts:

– Provides a GraphQL client to fetch and mutate data.

– Built-in support for caching, pagination, mutations, and more.

– Allows colocating React components with their data dependencies.

– Optimizes data fetching via prefetching and caching strategies.

– Improves performance by reducing network requests.

By removing the need to manually construct queries and manage caching, Relay simplifies data fetching in large, complex applications like Facebook.

Flow

Flow is a static type checker developed by Facebook for identifying bugs in JavaScript code. Features of Flow include:

– Adds static typing to JavaScript to improve developer productivity.

– Checks code for errors like undefined variables without needing to execute code.

– Catches bugs early through editor integration.

– Gradual adoption since it can check parts of a codebase.

– Infers types to reduce explicit annotations needed.

– Lightweight compared to solutions like TypeScript.

By bringing type safety to JavaScript, Flow helps Facebook catch bugs and ensure code quality as teams build complex web apps.

Backend Stack

On the backend, Facebook uses PHP, Hack, HHVM, MySQL, and other technologies to run its services at scale.

PHP

PHP has powered Facebook’s backend code since the company’s early days. Here are some key PHP facts:

– Open source, general purpose scripting language optimized for web development.

– Used to build most of Facebook’s early features like the News Feed.

– Powers backend services through PHP web frameworks like React and Hack.

– Interpreted language with dynamic typing allows rapid iteration.

– Large community of developers know PHP for web programming.

While Facebook has introduced other languages like Hack, PHP remains a major part of Facebook’s backend tech stack even today due to its flexibility and ecosystem.

Hack

Hack is an open source programming language developed by Facebook to enhance and gradually replace PHP. Key facts about Hack:

– Statically typed, allowing earlier bug catching.

– Interoperates seamlessly with PHP code.

– Adds features like generics, async functions, and more.

– Fast compilation via HipHop Virtual Machine (HHVM).

– Used by Facebook for its performance and type safety advantages.

Hack allows Facebook to gradually migrate legacy PHP services to a faster, safer language while retaining compatibility.

HHVM

HHVM (HipHop Virtual Machine) is the runtime engine optimized by Facebook to execute Hack and PHP code. HHVM provides:

– Just-in-time (JIT) compilation for faster execution compared to PHP.

– Type checking and other language features for Hack.

– Backward compatibility to run existing PHP code.

– Memory savings and better thread utilization.

– Open source and usable outside of Facebook.

HHVM allows Facebook to run PHP-based services much more efficiently at scale.

MySQL

MySQL is the open source relational database used by Facebook for operational data storage. Key facts:

– Open source RDBMS providing SQL interface to store and query data.

– Handles massive datasets and high throughput via partitioning and replication.

– Integrates with PHP/Hack for data access and ORM.

– Sharded and replicated across datacenters for availability.

– Supplemented by caching systems like Memcached.

MySQL gives Facebook a battle-tested, scalable data storage engine suitable for the vast amounts of data generated across Facebook.

Infrastructure Technologies

Supporting Facebook’s frontend and backend technologies is an array of infrastructure building blocks powering massive scale and efficiency.

Apache Thrift

Apache Thrift is a framework created by Facebook for scalable cross-language services. Key features:

– Defines data types and service interfaces in a language-neutral format.

– Generates code to build RPC clients and servers in a variety of languages.

– Serializes data structures efficiently for transport.

– Used internally for Facebook communication between datacenters.

Thrift enables Facebook services built in multiple languages to communicate with little overhead.

Haystack

Haystack is Facebook’s custom-built object storage system designed for photos and videos. Features:

– Stores hundreds of petabytes of media efficiently.

– Achieves high throughput to serve content fast.

– Cost-effective open source hardware with high density.

– Easy to operate at large scale.

Haystack gives Facebook an optimized storage subsystem purpose-built for media content.

TAO

TAO (The Associations and Objects Platform) is the software automation platform developed by Facebook for managing its compute infrastructure. Capabilities:

– Automates network control, load balancing, service deployment and more.

– Provides insights into infrastructure performance and issues.

– Enables fast iteration and rollout of new features.

– Reduces manual effort so engineers can focus on apps.

TAO has been instrumental in allowing Facebook to achieve massive scale and velocity of change.

Backbone

Backbone is Facebook’s private 100Gbps Ethernet network connecting its datacenters. Key facts:

– Spans tens of thousands of miles across fiber links.

– Carries Facebook’s internal traffic between regions and offices.

– Achieves very high throughput and low latency.

– Encrypts traffic end-to-end for security.

– Bypasses the public internet for control and speed.

The Backbone network enables Facebook to connect its infrastructure securely worldwide.

From LAMP Stack to Custom Stack

In Facebook’s early days, it relied on the typical open source LAMP (Linux, Apache, MySQL, PHP) stack that was popular for web applications at the time. But as Facebook grew to immense scale, it invested heavily in creating its own optimized custom technologies across all layers of the stack.

Early LAMP Stack

Facebook originally used the standard LAMP stack:

– Linux – Operating system running the servers.

– Apache – Web server software handling HTTP requests.

– MySQL – Open source relational database for storage.

– PHP – Scripting language for the application logic.

This combination of open source software was common for building web apps in the 2000’s. It allowed fast iteration in Facebook’s early stages.

Limitations at Scale

But the LAMP stack exhibited challenges as Facebook grew:

– PHP performance and efficiency became inadequate.

– MySQL didn’t scale well beyond a point.

– Apache wasn’t designed for massive concurrency.

– Managing hundreds of thousands of servers was tedious.

Standard LAMP was never designed to power one of the largest sites in the world.

Transition to Custom Stack

To overcome these challenges, Facebook invested in developing its own technologies:

– Built HHVM to massively improve PHP runtime performance.

– Replaced MySQL sharding with specialized storage engines like Haystack.

– Created software-defined infrastructure with tools like TAO.

– Invented custom networks like Backbone to connect datacenters.

The result is a unique end-to-end stack tailored for Facebook’s needs at scale.

Continuous Innovation

Facebook recognizes that technology development is never complete, and continues advancing its stack:

– Pushing the limits on data center design for efficiency.

– Exploring innovations like machine learning and computer vision.

– Contributing back to the open source community.

– Building the infrastructure of tomorrow with long-term R&D.

Facebook drives major infrastructure advancements through relentless improvement of every layer of its technology stack in support of its mission to connect the world.

Conclusion

Facebook’s technical infrastructure has evolved enormously from the early days of the LAMP stack to become a world-class, custom technology platform built to unique scale. Today, Facebook relies on a diverse collection of technologies across frontend, backend, infrastructure, and more – with many key innovations developed in-house. While open source remains at its roots, Facebook’s relentless drive for efficiency has led it to design purpose-built solutions tailored for performance at massive size and still advancing rapidly today through continued research and development across the stack.