Start 1 free chat request

1 free chat request

The method we chose to get text from one user to another involves loading an iframe on each Facebook page, and having that iframe's Javascript make an HTTP GET request over a persistent connection that doesn't return until the server has data for the client.

Glueing together PHP, Javascript, Erlang, and C is not a trivial matter. Thrift translates a service description into the RPC glue code necessary for making cross-language calls (marshalling arguments and responses over the wire) and has templates for servers and clients.

Since going open source a year ago (we had the gall to release it on April Fool's Day, 2007), the Thrift project has steadily grown and improved (with multiple iterations on the Erlang binding).

The naive implementation of sending a notification to all friends whenever a user comes online or goes offline has a worst case cost of O(average friendlist size * peak users * churn rate) messages/second, where churn rate is the frequency with which users come online and go offline, in events/second.

This is wildly inefficient to the point of being untenable, given that the average number of friends per user is measured in the hundreds, and the number of concurrent users during peak site usage is on the order of several millions.

Note that approach (a) changes the sending a chat message / loading a Facebook page from a one-to-one communication into a multicast to all online friends, while approach (b) ensures that users who are neither chatting nor browsing Facebook are nonetheless generating server load.

Another challenge is ensuring the timely delivery of the messages themselves.

Instagram had already let anyone streaming live invite a friend to join them, but by adding a request feature the possibilities for collaboration are greatly expanded. With the ability to see all pending requests, a host could pick a fan to join them live at random, or even selectively pick someone who just made an insightful comment in the chat.

Of course, there’s the worry that someone says something inappropriate when they join, but that’s not necessarily any riskier than allowing random people to comment on your posts.

To request to join a live video a viewer can tap a request button in the comments section.

Hosts see the request pop up in real time and can accept or deny, and also have access to a list of pending requests in case a bunch of different people are trying to join in.

This isn't by any means a new technique: it's a variation of Comet, specifically XHR long polling, and/or BOSH.