SlideShare a Scribd company logo
1 of 60
Download to read offline
Introduction Server-side scripting Client-side scripting Thrift Databases
Facebook’s open-source contributions
Geeks Anonymes
Damien Gerard
May 17th, 2017
Introduction Server-side scripting Client-side scripting Thrift Databases
Once a pony time. . .
The“face book”was the official printed book or web directory
consisting of individuals’ photographs and names, given to students.
On October 23, 2003 Harvard student Zuckerberg launches
Facemash.com: rate other people’s attractiveness. Shut down within
days. Zuckerberg faced expulsion for breaching security, violating
copyrights and individual privacy because he stole the student pictures
from the face book to populate Facemash.
On February 4, 2004 Zuckerberg and fellow Harvard students launch
TheFacebook.com, an unofficial online face book of Harvard
university students, with no material stolen from Harvard.
Users could search for other people and had privacy options to
prevent e.g. their name from being searched, to prevent student
outrage as for Facemash.
After one month, half of the Harvard undergraduate students had a
profile.
Introduction Server-side scripting Client-side scripting Thrift Databases
Once a pony time. . .
TheFacebook was promptly extended to other Boston universities and
eventually all US universities.
It dropped the“The”and became“Facebook”in August 2005.
Worldwide universities spread.
In September 2006, network extented beyond educational institutions
to anyone aged 13 with an email address.
On May 4th, 2017 Facebook reaches 2bn users.
Introduction Server-side scripting Client-side scripting Thrift Databases
Server-side scripting language – the choice of PHP
FB uses PHP as the server-side scripting language to generate HTML.
Despite its flaws and slowness, PHP is still by far the most used
among server-side scripting languages.
Nowadays, viable alternatives exist, but at the time, PHP was a good
choice for FB.
When FB faced scaling issues, their PHP codebase was already
several millions lines of code long.
FB kept and improved PHP instead of trying to rewrite their whole
codebase into another language.
Introduction Server-side scripting Client-side scripting Thrift Databases
HPHPc – PHP-to-C++ transpiler
The default PHP execution engine is Zend, an interpreter.
In November 2007, FB starts experiments to convert (transpile) PHP
code to C++, to compile it with a regular C++ compiler.
Called HPHPc, in 2009 it became FB’s sole execution engine
powering FB’s web servers.
FB adds HPHPd to allow developers to use break points, watches etc.
In early 2010, HPHPc open sourced as“Hip Hop for PHP”.
HPHPc was performant, but FB still needed something faster.
In 2010, FB started working on JIT compilation called HHVM.
HHVM took over FB’s entire web fleet in early 2013.
HPHPc is not deployed anywhere anymore.
Introduction Server-side scripting Client-side scripting Thrift Databases
HHVM – JIT compilation
HHVM stands for Hip Hop Virtual Machine (pretty much like what JVM is
for Java).
Why a Virtual Machine? This is unrelated with VMWare, VirtualBox and
the rest, which perform hardware virtualization.
The JVM compiles a Java source code to an intermediate language called
the Java Bytecode. A CPU cannot execute bytecode (it is not machine
code). The JVM translates the Java Bytecode to machine code. The JVM
actually defines an abstract CPU, or virtualizes the CPU.
The HHVM compiles PHP source code into Hip Hop Bytecode (HHBC).
Why an intermediate step? JIT (Just-in-Time) compilation of bytecode
allows adaptive optimization which can yield faster execution than static
compilation.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack
FB developed Hack, an evolution of PHP, tailored for the HHVM. Hack
mainly allows to use both dynamic and static typing:
function division(float $a, int $b) : float {
return $a / $b;
}
FB does not rewrite its PHP codebase into Hack. Old PHP code is kept.
New code is written in Hack. Hack code can call PHP code (and vice
versa). The HHVM runs both PHP and Hack. Hack deployed in
production in June 2012.
Hack’s code check tool was coined the“typechecker”(command
hh_client file.hh).
Hack is not a superset of PHP. Most bad PHP features are purposely
forbidden in Hack.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – static styping
PHP 5.x actually allowed typehints, but for class types only:
function enroll(Student $student, School $school) {
echo ’Enrolling ’ . $student->name . ’ in ’ . $school->name;
}
enroll(new Student("Damien"), new Program("Medicare"));
// Argument 2 passed to enroll() must be an instance of School.
Typehints of primitive types were not allowed in PHP 5.x:
function stringTest(string $str) { echo $str; }
stringTest(’definitely a string’); // Argument 1 passed to
// stringTest() must be an instance of string, string given.
Hack supports all typehints, for function parameters and return type.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – static styping
Static typing for class properties:
class C {
public static int $loggingLevel_ = 2;
private string $name_;
}
However, the type of local variables cannot be specified:
$x = 10;
$x = ’ten’; // valid
In Hack, local variables do not have types; local variables hold values,
which have types. At any point in the program, the typechecker knows
which type of value each variable holds. If a new value is assigned to a
variable, the typechecker will update its knownledge.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – multiple possible types
How to deal with
if(some_condition())
$x = 10; // int
else
$x = ’ten’; // string
The typechecker remembers that $x can be either an int or a string. The
following operations must support both int and string:
echo $x; // ok: can echo an int or a string
echo $x+20; // error: incompatible with a string
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – type inference
Type inference is type guessing when there is no annotation (no type
specified). Type inference is only function-local. When analyzing a
function and performing type inference, the typechecker never propagates
its guesses to called functions or caller functions.
function f($str) {
return ’Here is a string:’ . $str;
}
function main() {
echo f(’boo!’);
}
main();
We can infer the return type of f to be only a string. The typechecker will
not check main’s code with the known returned type of f.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – type inference
1 An inferred parameter or return type may impact numerous other
functions. This is not affordable considering FB’s large codebase. The
typechecker must run quickly. An inferred type is only used to check
the code of the current function, not called of caller functions.
2 If the types are specified, the typechecker only needs to check at most
the directly called and caller functions, not the whole tree of called
and caller functions, which puts a fairly low cap on the work required.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – number of parameters
PHP allowed
function f($a, $b) { }
f(1,2,3);
$a receives 1 and $b receives 2, third argument is forgotten. This is
accepted by PHP although the developer obviously made a mistake, which
may be tough to find. Hack forbids this.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – default values
Hack allows default values for arguments:
function f(string $str = ”, int $i = 0) { }
However, Hack forbids a null default value, whereas PHP allowed it:
function f(SomeClass $obj = null) { }
null is not really a default value. It depicts the lack of value. Hack forces
to declare the parameter nullable with
function f(?SomeClass $obj = null) { }
f();
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – default values
Example with a nullable string:
function takes_string(string $str) { }
function takes_nullable_string(?string $str) {
if($str !== null) {
takes_string($str);
}
}
takes_nullable_string(null);
takes_nullable_string(’hello’);
!is_null($str) may also be used instead of $str !== null.
The if is mandatory. Inside the if, the typechecker sees that $str is not
null, so takes_string can be called.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – generics, arrays, tuples
function max_and_index(array<float> $items) : (float, int) {
$max = -INF;
$maxIndex = -1;
foreach($items as $index => $value) {
if($value > $max) {
$max = $value;
$maxIndex = $index;
}
}
return tuple($max, $maxIndex);
}
Tuples are actually a restricted version of arrays.
Hack also introduced new collections (Vector, Set and Map) on top of
PHP’s array.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Callables
Pass function to a parameter:
function do_work(array<float> $items,
(function(int,float):string) $fct)
{
foreach($items as $index => $value) {
echo $fct($index, $value);
}
}
In PHP, a function passed as a parameter was a callable. Under the
hood, $fct is just an object. What can be done in Hack can be done in
PHP. Hack just gives ways to better express programs.
R
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Enumeration
PHP has no enums. Class constants or global constants had to be used.
enum CardSuit : int {
SPADES = 0; HEARTS = 1; CLUBS = 2; DIAMONDS = 3;
}
function suit_symbol(CardSuit $suit) : string {
switch($suit) {
case CardSuit::SPADES :
return "xe2x99xa4";
case CardSuit::CLUBS :
return "xe2x99xa7";
}
}
The typechecker reports“Switch statement nonexhaustive; the following
cases are missing: HEARTS, DIAMONDS”. default can also be used.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Switch statement
In switch statements, PHP allows multiple default statements.
Forbidden in Hack.
The developer must not forget break; at the end of a case. Hack
returns an error if no break; specified, unless the case is empty. If
fallthrough is intentional,“// FALLTHROUGH”must be added.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Shape
In PHP, most of the time, to represent a user with an id and a name, we do
not use a class with two properties, but an array with keys“id”and“name”.
Arrays shapes are meant to tell the Hack typechecker about the structure
of such an array:
type user = shape(’id’ => int, ’name’ => string);
function make_user(int $id, string $name) : user {
return shape(’id’ => $id, ’name’ => $name);
}
function make_user_2(int $id, string $name) : user {
$user = shape();
$user[’id’] = $id;
$user[’name’] = $name;
return $user;
}
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Closures and lambdas
Closure with array_map (PHP and Hack):
$id_to_user = [1=>’Mr1’, 2=>’Mr2’, 3=>’Mr3’, 4=>’Mr4’];
$user_ids = [2, 4];
$user_names = array_map(
function($id) use ($id_to_user) { return $id_to_user[$id]; },
$user_ids
);
The closure can be rewritten as a lambda expression in Hack:
$user_names = array_map($id ==> id_to_user[$id], $user_ids);
R
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Typechecker modes
PHP code is started with <?php. In Hack, it is <?hh with the choice of
mode.
1 Declarative mode: <?hh // decl
2 Partial mode: <?hh
3 Strict mode: <?hh // strict
R
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Declarative mode
Declarative mode : <?hh // decl
The typechercker does not check the static types. The typechecker only
checks for invalid syntax.
The declarative mode is a transition aid if one is migrating an existing
PHP codebase to Hack.
The HHVM/Hack package also provides tools to help migrate PHP code
to Hack, and Hack to PHP (if some users want to write in Hack but
cannot use HHVM for example).
R
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Partial mode
Partial mode : <?hh
The typechercker does all the typechecking it can, but does not require
typehints.
Top–level code is allowed but not typechecked. This is because top-level
code requires globals. Code should be wrapped in a function and have only
one top-level statement be a call to that function.
function main() {
// ...
}
main(); // top-level statement
R
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Strict mode
Strict mode : <?hh // strict
Anywhere there can be a type annotation, it must be specified, with a few
exceptions: constructors and destructors (no return type) and closures.
Strict mode cannot call PHP, whereas partial and declarative modes can.
But strict mode can call partial-mode or decl-mode Hack code.
In all web apps, there has to be at least one top-level statement to serve
as an entry point. So there will always be at least one partial-mode file.
If the code is 100% strict, it should be impossible to incur a type error at
runtime in the HHVM.
R
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Accessing superglobals
Strict mode does not allow superglobals. Accessor must be written in a
partial-mode file, called from strict-mode files.
function get_params() : array { return $_GET; }
But this does not contribute to any type safety. We should write instead
function get_param(arraykey $key) : ?string {
if(!array_key_exists($key, $_GET)) { return null; }
$value = $_GET[$key];
return is_string($value) ? $value : null;
}
Better: replace the return statement with
invariant(is_string($value), ’get_param: Expected string’);
return $value;
R
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Special attributes
There are several attributes (decorators) which can be written in front of
methods, e.g. <<__Override>> to report an error if there is no function
override.
R
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Special attributes
Common implementation to cache the result of a time-consuming
computation:
function factorize_impl($num) {
// some factorization algorithm
}
function factorize($num) {
static $cache = [];
if(!isset($cache[$num]))
$cache[$num] = factorize_impl($num);
return $cache[$num];
}
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Special attributes
HHVM handles the caching of functions results declared with the
<<__Memoize>> special attribute:
<<__Memoize>>
function factorize($num) {
// some factorization algorithm
}
HHVM makes no garantee that all results are kept forever. HHVM may
delete entries from the cache to free up memory.
Introduction Server-side scripting Client-side scripting Thrift Databases
Memcached
Memcached is an open-source (not developed by FB) distributed memory
caching system, to exploit unused RAM of multiple computers.
Facebook has around 300TB of data in Memcached processes. Memcached
is also used by YouTube, Reddit, Twitter, Tumblr, Wikipedia etc.
Most cloud providers sell Memcached services at part of their Platform as
a Service (PaaS), including Google App Engine, Amazon ElastiCache, IBM
Bluemix and Microsoft Azure.
Memcached can be used through Hack’s async capabilities.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – async
Hack’s async capabilities offer a way to use cooperative multitasking, in
which tasks voluntarily and explicitely cede the CPU to one another.
async function do_work() : Awaitable<string> {
// time-consuming computation
return ’ok’;
}
async function main() {
$msg = await do_work();
echo $msg;
}
await tells the HHVM to wait for the function result to be available.
await yields to another suspended async function, if there is any.
do_work() does not return a string. It returns an object that represents
a string which may or may not be available.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – async
HHVM provides await extensions for four kinds of operations:
1 queries to MySQL databases;
2 queries to Memcached;
3 reads and writes of stream resources;
4 cURL requests.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – MySQL query
async function fetch_db(int $id) : Awaitable<string> {
$conn = await AsyncMysqlClient::connect(localhost, 3306,
’dbname’,’admin’,’pass’);
$result = await $conn->queryf(
’SELECT name FROM users WHERE id=%d’, $id);
return $result->mapRows()[0][’name’];
}
queryf automatically performs appropriate escaping, to prevent SQL
injection attacks.
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – cURL request
async function fetch_web() : Awaitable<string> {
return await HHAsiocurl_exec(’https://www.example.com’);
}
Await multiple asynchronous operations and resume when all the results
are available:
async function fetch_all() : Awaitable<string> {
list($web, $db) = await HHAsiov(
array(fetch_web(), fetch_db(2)));
return $web . $db;
}
Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Memcached
Memcached is used through MCRouter, an open-source project developed
by FB to aid in scaling a Memcached deployment.
async function fetch_name(MCRouter $mcr, int $id) :
Awaitable<string>
{
$cachedResult = await $mcr->get($id);
if($cachedResult->isSucceeded()) {
return $cachedResult->getResult();
}
else {
$name = await fetch_db($id);
await $mcr->set($id, $name);
return $name;
}
}
Introduction Server-side scripting Client-side scripting Thrift Databases
XHP
XHP: represent an HTML tree as PHP/Hack objects, by means of
embedded XML-like syntax.
function build_paragraph(string $text, string $style): :div {
return <div style={$style}>
<p>{$text}</p>
</div>;
}
If a tag is misspelled or not closed, HHVM triggers a runtime error, which
may have gone unnoticed without XHP.
XHP enforces HTLM5 rules.
Introduction Server-side scripting Client-side scripting Thrift Databases
XHP
XHP prevents the cross-site scripting (XSS) vulnerability.
$user_name = $_REQUEST[’name’];
echo ’<html><head><title>Welcome</title></head>’;
echo ’<body>Welcome ’ . $user_name . ’</body></html>’;
If a user submits a string containing HTML markup, it will be interpreted
by the browser as part of the document object model (DOM). To avoid:
$user_name = htmlspecialchars($_REQUEST[’name’]);
Applying it exactly once is tough with large codebase, something XHP
automatically takes care of.
XHP dates back to 2009. Since 2015, 100% of FB’s web frontend code
uses XHP to generate HTML.
Introduction Server-side scripting Client-side scripting Thrift Databases
React
React is a JavaScript library for building user interfaces (UI) rendered
as HTML.
React only provides the“V”, the View layer, in the MVC template.
React was built at FB, was released in March 2013, open-sourced on
May 29, 2013.
Introduction Server-side scripting Client-side scripting Thrift Databases
React – Virtual DOM
The browser has its own Document Object Model (DOM). The key feature
of React is that it keeps an in-memory copy of the DOM, called the virtual
DOM.
The developer does not directly update the brower’s DOM to
add/modify/remove UI elements. Instead, the developer updates the
virtual DOM. React takes care of comparing the browser’s DOM and its
own virtual DOM, and updates the browser’s DOM as efficiently as
possible. If there are e.g. tabs on a page, React will only update the visible
tab, not the hidden ones.
Ember’s Glimmer engine is heavily inspired by React’s virtual DOM.
Introduction Server-side scripting Client-side scripting Thrift Databases
React – Create a simple element
<html><body>
<div id="app"></div>
<script src="https://fb.me/react-15.1.0.js"</script>
<script src="https://fb.me/react-dom-15.1.0.js"</script>
<script>
var title = React.createElement("h1",
{id:"titleId", className:"titleClass"}, "Hello World!");
ReactDOM.render(title, document.getElementById("app"));
</script>
</body></html>
which outputs
<div id="app">
<h1 id="titleId" class="titleClass">Hello World!</h1>
</div>
Introduction Server-side scripting Client-side scripting Thrift Databases
React – Create an element with children
A tag content may also be some children tags:
var obj = React.createElement("ul", null,
React.createElement("li", null, "1 lb Salmon"),
React.createElement("li", null, "1 cup Pine Nuts"),
React.createElement("li", null, "2 cups Butter Lettuce")
);
ReactDOM.render(obj, document.getElementById("app"));
which outputs
<div id="app">
<ul>
<li>1 lb Salmon</li><li>1 cup Pine Nuts</li>
<li>2 cups Butter Lettuce</li>
</ul>
</div>
Introduction Server-side scripting Client-side scripting Thrift Databases
React – Create elements with map
A li element can be created for each element in an array, with map:
var items = ["1 lb Salmon", "1 cup Pine Nuts",
"2 cups Butter Lettuce"];
var obj = React.createElement("ul", null,
items.map((ingredient, i) =>
React.createElement("li", { key: i }, ingredient)
)
);
ReactDOM.render(obj, document.getElementById("app"));
However, we need to write the specific array name (items). We would like
to receive the array as an input parameter.
Introduction Server-side scripting Client-side scripting Thrift Databases
React – Factory
const IngredientsList = ({ list }) =>
React.createElement("ul", null,
list.map((ingredient, i) =>
React.createElement("li", {key: i}, ingredient)
)
);
const IngredientsFactory = React.createFactory(IngredientsList);
const ingredients = ["1 lb pizza", "1 cup Pine Nuts",
"2 cups Butter Lettuce"];
ReactDOM.render(IngredientsFactory({ingredients}),
document.getElementById("app"));
Introduction Server-side scripting Client-side scripting Thrift Databases
React – JSX
JSX for React is what XHP is for PHP/Hack:
const Ingredients = ({ name, list }) =>
<h1>{name}</h1>
<ul className="ingredients">
{list.map((ingredient, i) =>
<li key={i}>{ingredient}</li>
)}
</ul>;
var ingredients = ["1 lb Salmon", "1 cup Pine Nuts",
"2 cups Butter Lettuce"];
ReactDOM.render(
<Ingredients name="Delicious recipe" list={ingredients} />,
document.getElementById("app"));
Introduction Server-side scripting Client-side scripting Thrift Databases
Flux
Flux is FB’s application architecture pattern for building user interfaces.
Example : input text area and button to add items to a todo list.
1 The View receives a click event.
2 The View uses the Dispatcher to broadcast the message (called an
action)“one wants to add an item to the todo list”.
3 The Store keeps the data, namely all the todo list items (as an array).
4 On startup, the Store told the Dispatcher that it wanted to be
informed about dispatched actions.
5 The Store handles the received action and adds the new item to its
array.
6 The Store tells the View to refresh, based on the Store’s data.
Introduction Server-side scripting Client-side scripting Thrift Databases
Flux example – HTML
<input type="text" id="new_todo" />
<button onclick="buttonClicked()">Add!</button>
<div id="div_todo_list">
</div>
Introduction Server-side scripting Client-side scripting Thrift Databases
Flux example – Store’s data
var todoStore = {
items: []
};
Introduction Server-side scripting Client-side scripting Thrift Databases
Flux example – Click event and Dispatcher
var appDispatcher = new Flux.Dispatcher();
function buttonClicked() {
var newText = document.getElementById("new_todo").value;
var action = {
actionName: ’add-to-todo’,
newTodoText: newText
};
appDispatcher.dispatch(action);
}
Introduction Server-side scripting Client-side scripting Thrift Databases
Flux example – Store receives and handles the action
appDispatcher.register(function(action) {
if (action.actionName === ’add-to-todo’) {
todoStore.items.push(action.newTodoText);
}
});
Introduction Server-side scripting Client-side scripting Thrift Databases
Flux example – Store asks View to refresh
var todoStoreEmitter = new EventEmitter();
appDispatcher.register(function(action) {
if (action.actionName === ’add-to-todo’) {
todoStore.items.push(action.newTodoText);
todoStoreEmitter.emit(’change’);
}
});
Introduction Server-side scripting Client-side scripting Thrift Databases
Flux example – View receives signal and refreshes
todoStoreEmitter.on(’change’, refreshView);
function refreshView() {
ReactDOM.render(
<TodoList todoItems={todoStore.items} />,
document.getElementById("div_todo_list"));
}
Introduction Server-side scripting Client-side scripting Thrift Databases
Flux example – View’s React
const TodoList = ({ todoItems }) =>
<ul>
{todoItems.map((itemText, i) =>
<li key={i}>{itemText}</li>
)}
</ul>;
ReactDOM.render(
<TodoList todoItems={[]} />,
document.getElementById("div_todo_list"));
Introduction Server-side scripting Client-side scripting Thrift Databases
Flux – Notes
There is only one Dispatcher in the application.
There may be multiple Stores and multiple Views.
The Views completely re-render upon change in the Stores’ data.
The re-rendering is on React’s virtual DOM, then React makes sure
to update the browser’s DOM very efficiently.
Flux is only a pattern, implemented in many frameworks, including
FB’s Flux, Reflux, Redux, Alt.
FB also developed and open sourced Flow, a static type checker for
JavaScript.
Introduction Server-side scripting Client-side scripting Thrift Databases
GraphQL
const FriendList = ({ friends }) =>
<div id="div_friend_list">
{friends.map(f => <Friend friend={f} />)}
</div>;
const Friend = ({ friend }) =>
<div id="div_friend">
<FriendImg urlImg={friend.urlImg} />
<span>{friend.name}</span>
<span>Mutual friends: {friend.numMutualFriends}</span>
</div>;
const FriendImg = ({ urlImg }) => <img src={urlImg} />;
What if we want to add an icon on each friend’s image to tell which
friends are verified users?
Introduction Server-side scripting Client-side scripting Thrift Databases
GraphQL
Each React component can be accompanied by a short GraphQL code
listing its data dependencies, independently of the other React
components.
Each React component could use e.g. Ajax to request its data to the
server. However, this would imply too many server round-trips.
Introduction Server-side scripting Client-side scripting Thrift Databases
Relay
Relay aggregates all the required data dependencies to reduce the number
of queries to the server.
Relay is an evolution of Flux. For instance, Relay uses only one Store.
Some FB projects use React/Flux, whereas some others use
React/Relay/GraphQL.
Introduction Server-side scripting Client-side scripting Thrift Databases
React Native
In March 2015 FB open sourced React Native, a framework for building
cross-platform applications which render natively on iOS and Android.
Netflix modified React to render on many televisions and DVD players.
Views in React Native are also written in JavaScript/HTML/CSS.
On April 18, 2017 FB announced React Fiber and Relay Modern.
Introduction Server-side scripting Client-side scripting Thrift Databases
Thrift
FB developed and open sourced Thrift, which is meant to build
cross-platform RPC services that can connect applications written in
different languages, over a network.
Introduction Server-side scripting Client-side scripting Thrift Databases
Databases
Cassandra (open sourced in 2008) is a NoSQL database designed to
handle large amounts of data across many servers, initially to power
FB’s Inbox Search. FB abandoned Cassandra in late 2010 for HBase.
Cassandra is still used by Apple, AppScale, Digg, Netflix, Reddit. . .
RocksDB is an embedded database, optimized to exploit many CPUs
and use efficiently SSDs. RocksDB is used by FB, Yahoo!, LinkedIn.
MyRocks is a RocksDB storage engine for MySQL.
FB developed and open sourced Hive and Presto which are SQL query
engines for analytics at scale. In 2013 FB gave up Hive/MapReduce
for Presto, to perform interactive queries against their 300PB data
warehouse.
Introduction Server-side scripting Client-side scripting Thrift Databases

More Related Content

What's hot

RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroChristopher Pecoraro
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiJérémy Derussé
 
Build restful ap is with python and flask
Build restful ap is with python and flaskBuild restful ap is with python and flask
Build restful ap is with python and flaskJeetendra singh
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkBo-Yi Wu
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with LaravelAbuzer Firdousi
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingChristopher Pecoraro
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Jesus Manuel Olivas
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Sumy PHP User Grpoup
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flaskJim Yeh
 
JWT - Sécurisez vos APIs
JWT - Sécurisez vos APIsJWT - Sécurisez vos APIs
JWT - Sécurisez vos APIsAndré Tapia
 
Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2Sumy PHP User Grpoup
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In DepthKirk Bushell
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSAntonio Peric-Mazar
 

What's hot (20)

RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
Slim Framework
Slim FrameworkSlim Framework
Slim Framework
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
 
Build restful ap is with python and flask
Build restful ap is with python and flaskBuild restful ap is with python and flask
Build restful ap is with python and flask
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
Flask Basics
Flask BasicsFlask Basics
Flask Basics
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
 
REST API Laravel
REST API LaravelREST API Laravel
REST API Laravel
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flask
 
JWT - Sécurisez vos APIs
JWT - Sécurisez vos APIsJWT - Sécurisez vos APIs
JWT - Sécurisez vos APIs
 
Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In Depth
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
 
Psr 7 symfony-day
Psr 7 symfony-dayPsr 7 symfony-day
Psr 7 symfony-day
 
New PHP Exploitation Techniques
New PHP Exploitation TechniquesNew PHP Exploitation Techniques
New PHP Exploitation Techniques
 

Similar to 170517 damien gérard framework facebook

Similar to 170517 damien gérard framework facebook (20)

Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Introduction to web and php mysql
Introduction to web and php mysqlIntroduction to web and php mysql
Introduction to web and php mysql
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
 
lab4_php
lab4_phplab4_php
lab4_php
 
lab4_php
lab4_phplab4_php
lab4_php
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
PHP Unit-1 Introduction to PHP
PHP Unit-1 Introduction to PHPPHP Unit-1 Introduction to PHP
PHP Unit-1 Introduction to PHP
 
Php manish
Php manishPhp manish
Php manish
 
Hack and HHVM
Hack and HHVMHack and HHVM
Hack and HHVM
 
PHP
PHPPHP
PHP
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolment
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbai
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generators
 
Php intro
Php introPhp intro
Php intro
 
Php intro
Php introPhp intro
Php intro
 
Php intro
Php introPhp intro
Php intro
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 

More from Geeks Anonymes

Programmer sous Unreal Engine
Programmer sous Unreal EngineProgrammer sous Unreal Engine
Programmer sous Unreal EngineGeeks Anonymes
 
Implémentation efficace et durable de processus métiers complexes
Implémentation efficace et durable de processus métiers complexesImplémentation efficace et durable de processus métiers complexes
Implémentation efficace et durable de processus métiers complexesGeeks Anonymes
 
Managing Open Source Licenses (Geeks Anonymes)
Managing Open Source Licenses (Geeks Anonymes)Managing Open Source Licenses (Geeks Anonymes)
Managing Open Source Licenses (Geeks Anonymes)Geeks Anonymes
 
Reprendre le contrôle de ses données
Reprendre le contrôle de ses donnéesReprendre le contrôle de ses données
Reprendre le contrôle de ses donnéesGeeks Anonymes
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes
 
Le rôle du testeur et le Blackbox testing
Le rôle du testeur et le Blackbox testingLe rôle du testeur et le Blackbox testing
Le rôle du testeur et le Blackbox testingGeeks Anonymes
 
Vulnérabilités au cœur des applications Web, menaces et contre-mesures
 Vulnérabilités au cœur des applications Web, menaces et contre-mesures Vulnérabilités au cœur des applications Web, menaces et contre-mesures
Vulnérabilités au cœur des applications Web, menaces et contre-mesuresGeeks Anonymes
 
191121 philippe teuwen cryptographie et attaques materielles
191121 philippe teuwen cryptographie et attaques materielles191121 philippe teuwen cryptographie et attaques materielles
191121 philippe teuwen cryptographie et attaques materiellesGeeks Anonymes
 
"Surfez couverts !" - Conseils de Cyber securité
"Surfez couverts !" - Conseils de Cyber securité "Surfez couverts !" - Conseils de Cyber securité
"Surfez couverts !" - Conseils de Cyber securité Geeks Anonymes
 
Introduction au développement mobile - développer une application iOS et Andr...
Introduction au développement mobile - développer une application iOS et Andr...Introduction au développement mobile - développer une application iOS et Andr...
Introduction au développement mobile - développer une application iOS et Andr...Geeks Anonymes
 
Intelligence artificielle et propriété intellectuelle
Intelligence artificielle et propriété intellectuelleIntelligence artificielle et propriété intellectuelle
Intelligence artificielle et propriété intellectuelleGeeks Anonymes
 
Pour une histoire plophonique du jeu video
Pour une histoire plophonique du jeu videoPour une histoire plophonique du jeu video
Pour une histoire plophonique du jeu videoGeeks Anonymes
 
Become Rick and famous, thanks to Open Source
Become Rick and famous, thanks to Open SourceBecome Rick and famous, thanks to Open Source
Become Rick and famous, thanks to Open SourceGeeks Anonymes
 
Reconnaissance vocale et création artistique
Reconnaissance vocale et création artistiqueReconnaissance vocale et création artistique
Reconnaissance vocale et création artistiqueGeeks Anonymes
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language ProcessingGeeks Anonymes
 
Sécurité, GDPR : vos données ont de la valeur
Sécurité, GDPR : vos données ont de la valeur Sécurité, GDPR : vos données ont de la valeur
Sécurité, GDPR : vos données ont de la valeur Geeks Anonymes
 

More from Geeks Anonymes (20)

Programmer sous Unreal Engine
Programmer sous Unreal EngineProgrammer sous Unreal Engine
Programmer sous Unreal Engine
 
Implémentation efficace et durable de processus métiers complexes
Implémentation efficace et durable de processus métiers complexesImplémentation efficace et durable de processus métiers complexes
Implémentation efficace et durable de processus métiers complexes
 
Managing Open Source Licenses (Geeks Anonymes)
Managing Open Source Licenses (Geeks Anonymes)Managing Open Source Licenses (Geeks Anonymes)
Managing Open Source Licenses (Geeks Anonymes)
 
Reprendre le contrôle de ses données
Reprendre le contrôle de ses donnéesReprendre le contrôle de ses données
Reprendre le contrôle de ses données
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage Go
 
Le rôle du testeur et le Blackbox testing
Le rôle du testeur et le Blackbox testingLe rôle du testeur et le Blackbox testing
Le rôle du testeur et le Blackbox testing
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Vulnérabilités au cœur des applications Web, menaces et contre-mesures
 Vulnérabilités au cœur des applications Web, menaces et contre-mesures Vulnérabilités au cœur des applications Web, menaces et contre-mesures
Vulnérabilités au cœur des applications Web, menaces et contre-mesures
 
191121 philippe teuwen cryptographie et attaques materielles
191121 philippe teuwen cryptographie et attaques materielles191121 philippe teuwen cryptographie et attaques materielles
191121 philippe teuwen cryptographie et attaques materielles
 
"Surfez couverts !" - Conseils de Cyber securité
"Surfez couverts !" - Conseils de Cyber securité "Surfez couverts !" - Conseils de Cyber securité
"Surfez couverts !" - Conseils de Cyber securité
 
Introduction au développement mobile - développer une application iOS et Andr...
Introduction au développement mobile - développer une application iOS et Andr...Introduction au développement mobile - développer une application iOS et Andr...
Introduction au développement mobile - développer une application iOS et Andr...
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
 
Test your code
Test your codeTest your code
Test your code
 
Intelligence artificielle et propriété intellectuelle
Intelligence artificielle et propriété intellectuelleIntelligence artificielle et propriété intellectuelle
Intelligence artificielle et propriété intellectuelle
 
Pour une histoire plophonique du jeu video
Pour une histoire plophonique du jeu videoPour une histoire plophonique du jeu video
Pour une histoire plophonique du jeu video
 
Become Rick and famous, thanks to Open Source
Become Rick and famous, thanks to Open SourceBecome Rick and famous, thanks to Open Source
Become Rick and famous, thanks to Open Source
 
Reconnaissance vocale et création artistique
Reconnaissance vocale et création artistiqueReconnaissance vocale et création artistique
Reconnaissance vocale et création artistique
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
 
Sécurité, GDPR : vos données ont de la valeur
Sécurité, GDPR : vos données ont de la valeur Sécurité, GDPR : vos données ont de la valeur
Sécurité, GDPR : vos données ont de la valeur
 
Modern sql
Modern sqlModern sql
Modern sql
 

Recently uploaded

『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxMario
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119APNIC
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxmibuzondetrabajo
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxNIMMANAGANTI RAMAKRISHNA
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxAndrieCagasanAkio
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 

Recently uploaded (11)

『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptx
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptx
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptx
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptx
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 

170517 damien gérard framework facebook

  • 1. Introduction Server-side scripting Client-side scripting Thrift Databases Facebook’s open-source contributions Geeks Anonymes Damien Gerard May 17th, 2017
  • 2. Introduction Server-side scripting Client-side scripting Thrift Databases Once a pony time. . . The“face book”was the official printed book or web directory consisting of individuals’ photographs and names, given to students. On October 23, 2003 Harvard student Zuckerberg launches Facemash.com: rate other people’s attractiveness. Shut down within days. Zuckerberg faced expulsion for breaching security, violating copyrights and individual privacy because he stole the student pictures from the face book to populate Facemash. On February 4, 2004 Zuckerberg and fellow Harvard students launch TheFacebook.com, an unofficial online face book of Harvard university students, with no material stolen from Harvard. Users could search for other people and had privacy options to prevent e.g. their name from being searched, to prevent student outrage as for Facemash. After one month, half of the Harvard undergraduate students had a profile.
  • 3. Introduction Server-side scripting Client-side scripting Thrift Databases Once a pony time. . . TheFacebook was promptly extended to other Boston universities and eventually all US universities. It dropped the“The”and became“Facebook”in August 2005. Worldwide universities spread. In September 2006, network extented beyond educational institutions to anyone aged 13 with an email address. On May 4th, 2017 Facebook reaches 2bn users.
  • 4. Introduction Server-side scripting Client-side scripting Thrift Databases Server-side scripting language – the choice of PHP FB uses PHP as the server-side scripting language to generate HTML. Despite its flaws and slowness, PHP is still by far the most used among server-side scripting languages. Nowadays, viable alternatives exist, but at the time, PHP was a good choice for FB. When FB faced scaling issues, their PHP codebase was already several millions lines of code long. FB kept and improved PHP instead of trying to rewrite their whole codebase into another language.
  • 5. Introduction Server-side scripting Client-side scripting Thrift Databases HPHPc – PHP-to-C++ transpiler The default PHP execution engine is Zend, an interpreter. In November 2007, FB starts experiments to convert (transpile) PHP code to C++, to compile it with a regular C++ compiler. Called HPHPc, in 2009 it became FB’s sole execution engine powering FB’s web servers. FB adds HPHPd to allow developers to use break points, watches etc. In early 2010, HPHPc open sourced as“Hip Hop for PHP”. HPHPc was performant, but FB still needed something faster. In 2010, FB started working on JIT compilation called HHVM. HHVM took over FB’s entire web fleet in early 2013. HPHPc is not deployed anywhere anymore.
  • 6. Introduction Server-side scripting Client-side scripting Thrift Databases HHVM – JIT compilation HHVM stands for Hip Hop Virtual Machine (pretty much like what JVM is for Java). Why a Virtual Machine? This is unrelated with VMWare, VirtualBox and the rest, which perform hardware virtualization. The JVM compiles a Java source code to an intermediate language called the Java Bytecode. A CPU cannot execute bytecode (it is not machine code). The JVM translates the Java Bytecode to machine code. The JVM actually defines an abstract CPU, or virtualizes the CPU. The HHVM compiles PHP source code into Hip Hop Bytecode (HHBC). Why an intermediate step? JIT (Just-in-Time) compilation of bytecode allows adaptive optimization which can yield faster execution than static compilation.
  • 7. Introduction Server-side scripting Client-side scripting Thrift Databases Hack FB developed Hack, an evolution of PHP, tailored for the HHVM. Hack mainly allows to use both dynamic and static typing: function division(float $a, int $b) : float { return $a / $b; } FB does not rewrite its PHP codebase into Hack. Old PHP code is kept. New code is written in Hack. Hack code can call PHP code (and vice versa). The HHVM runs both PHP and Hack. Hack deployed in production in June 2012. Hack’s code check tool was coined the“typechecker”(command hh_client file.hh). Hack is not a superset of PHP. Most bad PHP features are purposely forbidden in Hack.
  • 8. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – static styping PHP 5.x actually allowed typehints, but for class types only: function enroll(Student $student, School $school) { echo ’Enrolling ’ . $student->name . ’ in ’ . $school->name; } enroll(new Student("Damien"), new Program("Medicare")); // Argument 2 passed to enroll() must be an instance of School. Typehints of primitive types were not allowed in PHP 5.x: function stringTest(string $str) { echo $str; } stringTest(’definitely a string’); // Argument 1 passed to // stringTest() must be an instance of string, string given. Hack supports all typehints, for function parameters and return type.
  • 9. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – static styping Static typing for class properties: class C { public static int $loggingLevel_ = 2; private string $name_; } However, the type of local variables cannot be specified: $x = 10; $x = ’ten’; // valid In Hack, local variables do not have types; local variables hold values, which have types. At any point in the program, the typechecker knows which type of value each variable holds. If a new value is assigned to a variable, the typechecker will update its knownledge.
  • 10. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – multiple possible types How to deal with if(some_condition()) $x = 10; // int else $x = ’ten’; // string The typechecker remembers that $x can be either an int or a string. The following operations must support both int and string: echo $x; // ok: can echo an int or a string echo $x+20; // error: incompatible with a string
  • 11. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – type inference Type inference is type guessing when there is no annotation (no type specified). Type inference is only function-local. When analyzing a function and performing type inference, the typechecker never propagates its guesses to called functions or caller functions. function f($str) { return ’Here is a string:’ . $str; } function main() { echo f(’boo!’); } main(); We can infer the return type of f to be only a string. The typechecker will not check main’s code with the known returned type of f.
  • 12. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – type inference 1 An inferred parameter or return type may impact numerous other functions. This is not affordable considering FB’s large codebase. The typechecker must run quickly. An inferred type is only used to check the code of the current function, not called of caller functions. 2 If the types are specified, the typechecker only needs to check at most the directly called and caller functions, not the whole tree of called and caller functions, which puts a fairly low cap on the work required.
  • 13. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – number of parameters PHP allowed function f($a, $b) { } f(1,2,3); $a receives 1 and $b receives 2, third argument is forgotten. This is accepted by PHP although the developer obviously made a mistake, which may be tough to find. Hack forbids this.
  • 14. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – default values Hack allows default values for arguments: function f(string $str = ”, int $i = 0) { } However, Hack forbids a null default value, whereas PHP allowed it: function f(SomeClass $obj = null) { } null is not really a default value. It depicts the lack of value. Hack forces to declare the parameter nullable with function f(?SomeClass $obj = null) { } f();
  • 15. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – default values Example with a nullable string: function takes_string(string $str) { } function takes_nullable_string(?string $str) { if($str !== null) { takes_string($str); } } takes_nullable_string(null); takes_nullable_string(’hello’); !is_null($str) may also be used instead of $str !== null. The if is mandatory. Inside the if, the typechecker sees that $str is not null, so takes_string can be called.
  • 16. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – generics, arrays, tuples function max_and_index(array<float> $items) : (float, int) { $max = -INF; $maxIndex = -1; foreach($items as $index => $value) { if($value > $max) { $max = $value; $maxIndex = $index; } } return tuple($max, $maxIndex); } Tuples are actually a restricted version of arrays. Hack also introduced new collections (Vector, Set and Map) on top of PHP’s array.
  • 17. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Callables Pass function to a parameter: function do_work(array<float> $items, (function(int,float):string) $fct) { foreach($items as $index => $value) { echo $fct($index, $value); } } In PHP, a function passed as a parameter was a callable. Under the hood, $fct is just an object. What can be done in Hack can be done in PHP. Hack just gives ways to better express programs. R
  • 18. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Enumeration PHP has no enums. Class constants or global constants had to be used. enum CardSuit : int { SPADES = 0; HEARTS = 1; CLUBS = 2; DIAMONDS = 3; } function suit_symbol(CardSuit $suit) : string { switch($suit) { case CardSuit::SPADES : return "xe2x99xa4"; case CardSuit::CLUBS : return "xe2x99xa7"; } } The typechecker reports“Switch statement nonexhaustive; the following cases are missing: HEARTS, DIAMONDS”. default can also be used.
  • 19. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Switch statement In switch statements, PHP allows multiple default statements. Forbidden in Hack. The developer must not forget break; at the end of a case. Hack returns an error if no break; specified, unless the case is empty. If fallthrough is intentional,“// FALLTHROUGH”must be added.
  • 20. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Shape In PHP, most of the time, to represent a user with an id and a name, we do not use a class with two properties, but an array with keys“id”and“name”. Arrays shapes are meant to tell the Hack typechecker about the structure of such an array: type user = shape(’id’ => int, ’name’ => string); function make_user(int $id, string $name) : user { return shape(’id’ => $id, ’name’ => $name); } function make_user_2(int $id, string $name) : user { $user = shape(); $user[’id’] = $id; $user[’name’] = $name; return $user; }
  • 21. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Closures and lambdas Closure with array_map (PHP and Hack): $id_to_user = [1=>’Mr1’, 2=>’Mr2’, 3=>’Mr3’, 4=>’Mr4’]; $user_ids = [2, 4]; $user_names = array_map( function($id) use ($id_to_user) { return $id_to_user[$id]; }, $user_ids ); The closure can be rewritten as a lambda expression in Hack: $user_names = array_map($id ==> id_to_user[$id], $user_ids); R
  • 22. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Typechecker modes PHP code is started with <?php. In Hack, it is <?hh with the choice of mode. 1 Declarative mode: <?hh // decl 2 Partial mode: <?hh 3 Strict mode: <?hh // strict R
  • 23. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Declarative mode Declarative mode : <?hh // decl The typechercker does not check the static types. The typechecker only checks for invalid syntax. The declarative mode is a transition aid if one is migrating an existing PHP codebase to Hack. The HHVM/Hack package also provides tools to help migrate PHP code to Hack, and Hack to PHP (if some users want to write in Hack but cannot use HHVM for example). R
  • 24. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Partial mode Partial mode : <?hh The typechercker does all the typechecking it can, but does not require typehints. Top–level code is allowed but not typechecked. This is because top-level code requires globals. Code should be wrapped in a function and have only one top-level statement be a call to that function. function main() { // ... } main(); // top-level statement R
  • 25. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Strict mode Strict mode : <?hh // strict Anywhere there can be a type annotation, it must be specified, with a few exceptions: constructors and destructors (no return type) and closures. Strict mode cannot call PHP, whereas partial and declarative modes can. But strict mode can call partial-mode or decl-mode Hack code. In all web apps, there has to be at least one top-level statement to serve as an entry point. So there will always be at least one partial-mode file. If the code is 100% strict, it should be impossible to incur a type error at runtime in the HHVM. R
  • 26. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Accessing superglobals Strict mode does not allow superglobals. Accessor must be written in a partial-mode file, called from strict-mode files. function get_params() : array { return $_GET; } But this does not contribute to any type safety. We should write instead function get_param(arraykey $key) : ?string { if(!array_key_exists($key, $_GET)) { return null; } $value = $_GET[$key]; return is_string($value) ? $value : null; } Better: replace the return statement with invariant(is_string($value), ’get_param: Expected string’); return $value; R
  • 27. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Special attributes There are several attributes (decorators) which can be written in front of methods, e.g. <<__Override>> to report an error if there is no function override. R
  • 28. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Special attributes Common implementation to cache the result of a time-consuming computation: function factorize_impl($num) { // some factorization algorithm } function factorize($num) { static $cache = []; if(!isset($cache[$num])) $cache[$num] = factorize_impl($num); return $cache[$num]; }
  • 29. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Special attributes HHVM handles the caching of functions results declared with the <<__Memoize>> special attribute: <<__Memoize>> function factorize($num) { // some factorization algorithm } HHVM makes no garantee that all results are kept forever. HHVM may delete entries from the cache to free up memory.
  • 30. Introduction Server-side scripting Client-side scripting Thrift Databases Memcached Memcached is an open-source (not developed by FB) distributed memory caching system, to exploit unused RAM of multiple computers. Facebook has around 300TB of data in Memcached processes. Memcached is also used by YouTube, Reddit, Twitter, Tumblr, Wikipedia etc. Most cloud providers sell Memcached services at part of their Platform as a Service (PaaS), including Google App Engine, Amazon ElastiCache, IBM Bluemix and Microsoft Azure. Memcached can be used through Hack’s async capabilities.
  • 31. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – async Hack’s async capabilities offer a way to use cooperative multitasking, in which tasks voluntarily and explicitely cede the CPU to one another. async function do_work() : Awaitable<string> { // time-consuming computation return ’ok’; } async function main() { $msg = await do_work(); echo $msg; } await tells the HHVM to wait for the function result to be available. await yields to another suspended async function, if there is any. do_work() does not return a string. It returns an object that represents a string which may or may not be available.
  • 32. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – async HHVM provides await extensions for four kinds of operations: 1 queries to MySQL databases; 2 queries to Memcached; 3 reads and writes of stream resources; 4 cURL requests.
  • 33. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – MySQL query async function fetch_db(int $id) : Awaitable<string> { $conn = await AsyncMysqlClient::connect(localhost, 3306, ’dbname’,’admin’,’pass’); $result = await $conn->queryf( ’SELECT name FROM users WHERE id=%d’, $id); return $result->mapRows()[0][’name’]; } queryf automatically performs appropriate escaping, to prevent SQL injection attacks.
  • 34. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – cURL request async function fetch_web() : Awaitable<string> { return await HHAsiocurl_exec(’https://www.example.com’); } Await multiple asynchronous operations and resume when all the results are available: async function fetch_all() : Awaitable<string> { list($web, $db) = await HHAsiov( array(fetch_web(), fetch_db(2))); return $web . $db; }
  • 35. Introduction Server-side scripting Client-side scripting Thrift Databases Hack – Memcached Memcached is used through MCRouter, an open-source project developed by FB to aid in scaling a Memcached deployment. async function fetch_name(MCRouter $mcr, int $id) : Awaitable<string> { $cachedResult = await $mcr->get($id); if($cachedResult->isSucceeded()) { return $cachedResult->getResult(); } else { $name = await fetch_db($id); await $mcr->set($id, $name); return $name; } }
  • 36. Introduction Server-side scripting Client-side scripting Thrift Databases XHP XHP: represent an HTML tree as PHP/Hack objects, by means of embedded XML-like syntax. function build_paragraph(string $text, string $style): :div { return <div style={$style}> <p>{$text}</p> </div>; } If a tag is misspelled or not closed, HHVM triggers a runtime error, which may have gone unnoticed without XHP. XHP enforces HTLM5 rules.
  • 37. Introduction Server-side scripting Client-side scripting Thrift Databases XHP XHP prevents the cross-site scripting (XSS) vulnerability. $user_name = $_REQUEST[’name’]; echo ’<html><head><title>Welcome</title></head>’; echo ’<body>Welcome ’ . $user_name . ’</body></html>’; If a user submits a string containing HTML markup, it will be interpreted by the browser as part of the document object model (DOM). To avoid: $user_name = htmlspecialchars($_REQUEST[’name’]); Applying it exactly once is tough with large codebase, something XHP automatically takes care of. XHP dates back to 2009. Since 2015, 100% of FB’s web frontend code uses XHP to generate HTML.
  • 38. Introduction Server-side scripting Client-side scripting Thrift Databases React React is a JavaScript library for building user interfaces (UI) rendered as HTML. React only provides the“V”, the View layer, in the MVC template. React was built at FB, was released in March 2013, open-sourced on May 29, 2013.
  • 39. Introduction Server-side scripting Client-side scripting Thrift Databases React – Virtual DOM The browser has its own Document Object Model (DOM). The key feature of React is that it keeps an in-memory copy of the DOM, called the virtual DOM. The developer does not directly update the brower’s DOM to add/modify/remove UI elements. Instead, the developer updates the virtual DOM. React takes care of comparing the browser’s DOM and its own virtual DOM, and updates the browser’s DOM as efficiently as possible. If there are e.g. tabs on a page, React will only update the visible tab, not the hidden ones. Ember’s Glimmer engine is heavily inspired by React’s virtual DOM.
  • 40. Introduction Server-side scripting Client-side scripting Thrift Databases React – Create a simple element <html><body> <div id="app"></div> <script src="https://fb.me/react-15.1.0.js"</script> <script src="https://fb.me/react-dom-15.1.0.js"</script> <script> var title = React.createElement("h1", {id:"titleId", className:"titleClass"}, "Hello World!"); ReactDOM.render(title, document.getElementById("app")); </script> </body></html> which outputs <div id="app"> <h1 id="titleId" class="titleClass">Hello World!</h1> </div>
  • 41. Introduction Server-side scripting Client-side scripting Thrift Databases React – Create an element with children A tag content may also be some children tags: var obj = React.createElement("ul", null, React.createElement("li", null, "1 lb Salmon"), React.createElement("li", null, "1 cup Pine Nuts"), React.createElement("li", null, "2 cups Butter Lettuce") ); ReactDOM.render(obj, document.getElementById("app")); which outputs <div id="app"> <ul> <li>1 lb Salmon</li><li>1 cup Pine Nuts</li> <li>2 cups Butter Lettuce</li> </ul> </div>
  • 42. Introduction Server-side scripting Client-side scripting Thrift Databases React – Create elements with map A li element can be created for each element in an array, with map: var items = ["1 lb Salmon", "1 cup Pine Nuts", "2 cups Butter Lettuce"]; var obj = React.createElement("ul", null, items.map((ingredient, i) => React.createElement("li", { key: i }, ingredient) ) ); ReactDOM.render(obj, document.getElementById("app")); However, we need to write the specific array name (items). We would like to receive the array as an input parameter.
  • 43. Introduction Server-side scripting Client-side scripting Thrift Databases React – Factory const IngredientsList = ({ list }) => React.createElement("ul", null, list.map((ingredient, i) => React.createElement("li", {key: i}, ingredient) ) ); const IngredientsFactory = React.createFactory(IngredientsList); const ingredients = ["1 lb pizza", "1 cup Pine Nuts", "2 cups Butter Lettuce"]; ReactDOM.render(IngredientsFactory({ingredients}), document.getElementById("app"));
  • 44. Introduction Server-side scripting Client-side scripting Thrift Databases React – JSX JSX for React is what XHP is for PHP/Hack: const Ingredients = ({ name, list }) => <h1>{name}</h1> <ul className="ingredients"> {list.map((ingredient, i) => <li key={i}>{ingredient}</li> )} </ul>; var ingredients = ["1 lb Salmon", "1 cup Pine Nuts", "2 cups Butter Lettuce"]; ReactDOM.render( <Ingredients name="Delicious recipe" list={ingredients} />, document.getElementById("app"));
  • 45. Introduction Server-side scripting Client-side scripting Thrift Databases Flux Flux is FB’s application architecture pattern for building user interfaces. Example : input text area and button to add items to a todo list. 1 The View receives a click event. 2 The View uses the Dispatcher to broadcast the message (called an action)“one wants to add an item to the todo list”. 3 The Store keeps the data, namely all the todo list items (as an array). 4 On startup, the Store told the Dispatcher that it wanted to be informed about dispatched actions. 5 The Store handles the received action and adds the new item to its array. 6 The Store tells the View to refresh, based on the Store’s data.
  • 46. Introduction Server-side scripting Client-side scripting Thrift Databases Flux example – HTML <input type="text" id="new_todo" /> <button onclick="buttonClicked()">Add!</button> <div id="div_todo_list"> </div>
  • 47. Introduction Server-side scripting Client-side scripting Thrift Databases Flux example – Store’s data var todoStore = { items: [] };
  • 48. Introduction Server-side scripting Client-side scripting Thrift Databases Flux example – Click event and Dispatcher var appDispatcher = new Flux.Dispatcher(); function buttonClicked() { var newText = document.getElementById("new_todo").value; var action = { actionName: ’add-to-todo’, newTodoText: newText }; appDispatcher.dispatch(action); }
  • 49. Introduction Server-side scripting Client-side scripting Thrift Databases Flux example – Store receives and handles the action appDispatcher.register(function(action) { if (action.actionName === ’add-to-todo’) { todoStore.items.push(action.newTodoText); } });
  • 50. Introduction Server-side scripting Client-side scripting Thrift Databases Flux example – Store asks View to refresh var todoStoreEmitter = new EventEmitter(); appDispatcher.register(function(action) { if (action.actionName === ’add-to-todo’) { todoStore.items.push(action.newTodoText); todoStoreEmitter.emit(’change’); } });
  • 51. Introduction Server-side scripting Client-side scripting Thrift Databases Flux example – View receives signal and refreshes todoStoreEmitter.on(’change’, refreshView); function refreshView() { ReactDOM.render( <TodoList todoItems={todoStore.items} />, document.getElementById("div_todo_list")); }
  • 52. Introduction Server-side scripting Client-side scripting Thrift Databases Flux example – View’s React const TodoList = ({ todoItems }) => <ul> {todoItems.map((itemText, i) => <li key={i}>{itemText}</li> )} </ul>; ReactDOM.render( <TodoList todoItems={[]} />, document.getElementById("div_todo_list"));
  • 53. Introduction Server-side scripting Client-side scripting Thrift Databases Flux – Notes There is only one Dispatcher in the application. There may be multiple Stores and multiple Views. The Views completely re-render upon change in the Stores’ data. The re-rendering is on React’s virtual DOM, then React makes sure to update the browser’s DOM very efficiently. Flux is only a pattern, implemented in many frameworks, including FB’s Flux, Reflux, Redux, Alt. FB also developed and open sourced Flow, a static type checker for JavaScript.
  • 54. Introduction Server-side scripting Client-side scripting Thrift Databases GraphQL const FriendList = ({ friends }) => <div id="div_friend_list"> {friends.map(f => <Friend friend={f} />)} </div>; const Friend = ({ friend }) => <div id="div_friend"> <FriendImg urlImg={friend.urlImg} /> <span>{friend.name}</span> <span>Mutual friends: {friend.numMutualFriends}</span> </div>; const FriendImg = ({ urlImg }) => <img src={urlImg} />; What if we want to add an icon on each friend’s image to tell which friends are verified users?
  • 55. Introduction Server-side scripting Client-side scripting Thrift Databases GraphQL Each React component can be accompanied by a short GraphQL code listing its data dependencies, independently of the other React components. Each React component could use e.g. Ajax to request its data to the server. However, this would imply too many server round-trips.
  • 56. Introduction Server-side scripting Client-side scripting Thrift Databases Relay Relay aggregates all the required data dependencies to reduce the number of queries to the server. Relay is an evolution of Flux. For instance, Relay uses only one Store. Some FB projects use React/Flux, whereas some others use React/Relay/GraphQL.
  • 57. Introduction Server-side scripting Client-side scripting Thrift Databases React Native In March 2015 FB open sourced React Native, a framework for building cross-platform applications which render natively on iOS and Android. Netflix modified React to render on many televisions and DVD players. Views in React Native are also written in JavaScript/HTML/CSS. On April 18, 2017 FB announced React Fiber and Relay Modern.
  • 58. Introduction Server-side scripting Client-side scripting Thrift Databases Thrift FB developed and open sourced Thrift, which is meant to build cross-platform RPC services that can connect applications written in different languages, over a network.
  • 59. Introduction Server-side scripting Client-side scripting Thrift Databases Databases Cassandra (open sourced in 2008) is a NoSQL database designed to handle large amounts of data across many servers, initially to power FB’s Inbox Search. FB abandoned Cassandra in late 2010 for HBase. Cassandra is still used by Apple, AppScale, Digg, Netflix, Reddit. . . RocksDB is an embedded database, optimized to exploit many CPUs and use efficiently SSDs. RocksDB is used by FB, Yahoo!, LinkedIn. MyRocks is a RocksDB storage engine for MySQL. FB developed and open sourced Hive and Presto which are SQL query engines for analytics at scale. In 2013 FB gave up Hive/MapReduce for Presto, to perform interactive queries against their 300PB data warehouse.
  • 60. Introduction Server-side scripting Client-side scripting Thrift Databases