Chapter 12 Design Facebook

12.0.1 Slack?

2016

  • Persistent Group Messaging

4M DAU, 6M WAU, 3M peak CCC(concurrent connections) 2+H per wday for each active user 10+ per week

MySQL+PHP(HHVM)

Sharding by team:
select db_shard from teams where domain=%domain in main0(sharding DB) select * from channels where teamid=711

Why MySQL? MMR - conflict websocket uri: wss rtm.start job queue(redis) - PUB/SUB

  • flannel

https://slack.engineering/flannel-an-application-level-edge-cache-to-make-slack-scale-b8a6400e2f6b

This lazy loading is the ideological birthplace of Flannel, an application-level caching service developed in-house and deployed to our edge points-of-presence. Upon client startup, Flannel caches relevant data of users, channels, bots, and more. It then provides query APIs for clients to fetch upon demand. It foresees data that will be requested next and pushes data proactively to clients. For example, let’s say you mention a colleague in a channel: While broadcasting that message to people in the channel, Flannel sees that some clients have not loaded the information about the mentioned user recently. It sends the user data to those clients just before sending the message to save them a round-trip query.

2018

PPT: Flannel

12.0.2 Facebook messenger/Whatsapp

  • security
  • 1o1 text

  • send/delivery/read confirmation

  • push notification

haystack, Cassandra(LSM-Tree container), Cold Start, SPOF

https://stackoverflow.com/questions/1509743/what-is-a-good-way-to-transfer-binary-data-to-a-http-rest-api-service

http://blog.gainlo.co/index.php/2016/04/19/design-facebook-chat-function/

http://massivetechinterview.blogspot.com/2015/07/design-chat-server-hello-world.html

https://stackoverflow.com/questions/17448061/how-many-system-resources-will-be-held-for-keeping-1-000-000-websocket-open/17451928#17451928

http://systemdesigns.blogspot.com/2015/12/facebook-chat-messeger.html

API:

sendMessage(senderId, recepientId, messageContent, clientMessageId)

ConversationResult fetchConversation(userId, pageNumber, pageSize, lastUpdatedTimestamp)

Function 1: Real-time presence notification:

The most resource-intensive operation performed in a chat system is not sending messages.

It is rather keeping each online user aware of the online-idle-offline states of their friends,

so that conversations can begin.

  • How do we know if someone is online?

https://www.quora.com/Why-was-Erlang-chosen-for-use-in-Facebook-chat

http://www.cnblogs.com/liuyong/archive/2011/07/01/2095487.html
http://www.cnblogs.com/0201zcr/p/4694945.html

https://jdrch.wordpress.com/2013/04/18/ignore-facebook-messengers-active-now-or-online-presence-info-its-inaccurate/

https://www.facebook.com/notes/facebook-engineering/facebook-chat/14218138919/