Chapter 12 Design Facebook

12.0.1 Slack?


  • Persistent Group Messaging

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


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

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.


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


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?