When you open your browser and type facebook.com, the seamless experience of scrolling through your News Feed involves a complex orchestration of technologies. Understanding what Facebook is written in reveals a sophisticated blend of programming languages, frameworks, and infrastructure designed for scale and performance.
The Core Backend: PHP and HHVM
For the majority of its history, the Facebook application has been built primarily using PHP. This choice was foundational to its early growth, allowing for rapid development cycles and easy deployment across thousands of servers. To overcome the performance limitations traditionally associated with PHP, Facebook developed the HipHop Virtual Machine (HHVM). This just-in-time (JIT) compiler transforms PHP code into highly efficient C++ before execution, dramatically improving request handling speed and reducing server load.
Evolution and Modern Infrastructure
From Hack to Production
To address the challenges of maintaining a large PHP codebase, Facebook created Hack. Hack is a statically-typed superset of PHP that runs on the HHVM. It introduces features like type annotations and async functions while maintaining full backward compatibility with existing PHP code. This language allows developers to write more robust and maintainable code without abandoning the performance benefits of the HHVM runtime.
On the infrastructure side, Facebook relies heavily on a custom-built platform known as TAO. This distributed data store is the backbone of the social graph, handling the complex relationships between users, posts, and connections. The backend services interacting with TAO are predominantly written in Hack and PHP, optimized for the low-latency demands of a global social network.
Frontend Development and User Interface
The user interface you interact with is primarily rendered using JavaScript. Facebook developed React, an open-source library for building complex user interfaces, to manage the dynamic content of the News Feed. React's component-based architecture allows for efficient updates and a responsive experience, handling real-time data streams without requiring full page reloads.
CSS-in-JS libraries are also employed to manage the styling of components at scale. This frontend stack is bundled using modern tools to ensure fast load times and optimal performance across a wide variety of devices and network conditions.
Mobile Applications and Native Integration
The official Facebook mobile apps for iOS and Android utilize native development languages to deliver the best possible performance and user experience. The iOS application is written in Swift and Objective-C, while the Android application is built using Kotlin and Java. These native layers interact with Facebook's backend services, including the core API written in PHP and Hack, to synchronize data and provide feature parity across platforms.
Supporting Technologies and Data Systems
Beyond the primary languages, Facebook's ecosystem relies on a multitude of other technologies. Erlang is used for specific backend services requiring high concurrency and fault tolerance, such as chat infrastructure. Python is often employed for data analysis, machine learning, and automation scripts. The database layer is equally diverse, utilizing MySQL for primary data storage, alongside systems like RocksDB for caching and Hadoop for large-scale data processing.