Top 5 Programming Languages Mostly Used By Facebook Programmers To Developed All Product

By Kimberly Cook |Email | Feb 19, 2019 | 473430 Views

The frontend is written in PHP (programming language).  Much of it is written using XHP, and the runtime is HipHop for PHP.  Like most websites, there's a lot of JavaScript (programming language) running in the users' browsers.

Most of the backend services are written in C (programming language), C++ and Java.  A lot of the C++ services rely on Boost (C++ libraries).  Many of the internal tools and some glue code are written in Python (programming language).  One of the services that underlie Chat, the channel servers (see ), is written in Erlang (programming language).  The backend services and the web frontend communicate using Apache Thrift. The iPhone app and iOS SDK are written in Objective-C (programming language).
OCaml (programming language), Haskell (programming language), and Ruby (programming language) are used internally, but as far as I know, they don't power anything available on the website.

Initially, the whole code for Facebook was written in PHP by Zuckerberg and Dustin Moskowitz. It is used for the front-end along with Javascript. PHP was a good choice as it is an open script acting as a glue to HTML front-end and C++ application logic back-end.

PHP, being a scripting language, is relatively slow when compared to code that runs natively on a server. HipHop converts PHP into C++ code which can then be compiled for better performance.

At the back-end, they use C, C++, Java, and Python. Proxygen is a high-performance C++ HTTP framework. It is a collection of C++ HTTP libraries, including an easy-to-use HTTP server.

Erlang is used to power the backend of chat service, handling more than 700 million active users. Facebook Chat system is running on ejabberd based server.

One of the key values of Facebook is to move fast. Simple to learn, simple to write, simple to read, and simple to debug. 

HipHop for PHP isn't technically a compiler itself. Rather it is a   source code transformer. HipHop programmatically transforms your PHP   source code into highly optimized C++ and then uses g++ to compile it.   HipHop executes the source code in a semantically equivalent manner and sacrifices some rarely used features - such as eval() - in exchange for improved performance. HipHop includes a code transformer,   a reimplementation of PHP's runtime system, and a rewrite of many common PHP Extensions to take advantage of these performance optimizations.
Scaling PHP as a Scripting Language     
PHP's roots are those of a scripting language, like Perl, Python, and   Ruby, all of which have major benefits in terms of programmer productivity and the ability to iterate quickly on products. This is compared to more traditional compiled languages like C++ and interpreted languages like Java. On the other hand, scripting languages are known to generally be less efficient when it comes to   CPU and memory usage. Because of this, it's been challenging to scale   Facebook to over 400 billion PHP-based page views every month.     
One common way to address these inefficiencies is to rewrite the more complex parts of your PHP application directly in C++ as PHP   Extensions. This largely transforms PHP into a glue language between your front end HTML and application logic in C++. From a technical perspective this works well, but drastically reduces the number of engineers who are able to work on your entire application. Learning   C++ is only the first step to writing PHP Extensions, the second is understanding the Zend APIs. Given that our engineering team is relatively small - there are over one million users to every engineer   - we can't afford to make parts of our codebase less accessible than others
Scaling Facebook is particularly challenging because almost every page view is a logged-in user with a customized experience. When you view   your home page we need to look up all of your friends, query their   most relevant updates (from a custom service we've built called   Multifeed), filter the results based on your privacy settings, then   fill out the stories with comments, photos, likes, and all the rich   data that people love about Facebook. All of this in just under a   second. HipHop allows us to write the logic that does the final page assembly in PHP and iterate it quickly while relying on custom back-end services in C++, Erlang, Java, or Python to service the News   Feed, search, Chat, and other core parts of the site.     
Since 2007 we've thought about a few different ways to solve these problems and have even tried implementing a few of them. The common suggestion is to just rewrite Facebook in another language, but given the complexity and speed of development of the site, this would take some time to accomplish. We've rewritten aspects of the Zend Engine -   PHP's internals - and contributed those patches back into the PHP   project, but ultimately haven't seen the sort of performance increases that are needed. HipHop's benefits are nearly transparent to our development speed.
Hacking Up HipHop     
One night at a Hackathon a few years ago (see Prime Time Hack), I   started my first piece of code transforming PHP into C++. The languages are fairly similar syntactically and C++ drastically outperforms PHP when it comes to both CPU and memory usage. Even PHP   itself is written in C. We knew that it was impossible to successfully rewrite an entire codebase of this size by hand, but wondered what would happen if we built a system to do it programmatically.  
Finding new ways to improve PHP performance isn't a new concept. At run time the Zend Engine turns your PHP source into opcodes which are then run through the Zend Virtual Machine. Open source projects such as APC and eAccelerator cache this output and are used by the majority of PHP powered websites. There's also Zend Server, a commercial product which makes PHP faster via opcode optimization and caching.   Instead, we were thinking about transforming PHP source directly into   C++ which can then be turned into native machine code. Even compiling   PHP isn't a new idea, open source projects like Roadsend and php compile PHP to C, Quercus compiles PHP to Java, and Phalanger compiles   PHP to. .Net.     
Needless to say, it took longer than that single Hackathon. Eight months later, I had enough code to demonstrate it is indeed possible   to run faster with compiled code. We quickly added Iain Proctor and   Minghui Yang to the team to speed up the pace of the project. We spent   the next ten months finishing up all the coding and the following six   months testing on production servers. We are proud to say that at this   point, we are serving over 90% of our Web traffic using HipHop, all   only six months after deployment.

How HipHop Works     
The main challenge of the project was bridging the gap between PHP and   C++. PHP is a scripting language with dynamic, weak typing. C++ is a   compiled language with static typing. While PHP allows you to write magical dynamic features, most PHP is relatively straightforward. It's   more likely that you see if (...) {...} else {..} than it is to see   function foo($x) { include $x; }. This is where we gain in performance. Whenever possible our generated code uses static binding for functions and variables. We also use type inference to pick the most specific type possible for our variables and thus save memory.     
The transformation process includes three main steps:    
Static analysis where we collect information on who declares what and dependencies,
Type inference where we choose the most specific type between C++ scalars, String, Array, classes, Object, and Variant, and
Code generation which for the most part is a direct correspondence from PHP statements and expressions to C++ statements and expressions.

Source: HOB