Design Facebook Messenger

Problem Statement:

Step-1: What is Facebook Messenger ?


Step-2: Requirements and Goals of the System


Step-3: Capacity Estimation and Constraints

Storage Estimation:
Bandwidth Estimation:


Step-4: High Level Design

Detailed Workflow
  1. User-A sends a message to User-B through the chat server.
  2. The server receives the message and sends an acknowledgment to User-A.
  3. The server stores the message in its database and sends the message to User-B.
  4. User-B receives the message and sends the acknowledgment to the server.
  5. The server notifies User-A that the message has been delivered successfully to User-B.



Step-5: Detailed Component Design


a) Messages Handling
How would we efficiently send/receive messages ?
How will clients maintain an open connection with the server ?
How can server keep track of all opened connection to efficiently redirect messages to the users ?
What will happen when the server receives a message for a user who has gone offline ?
How many chat servers we need ?
How to know which server holds the connection to which user ?
How should the chat server process a ‘deliver message’ request ?
How does the messenger maintain the sequencing of the messages ?


b) Storing and Retrieving Messages from DB
Which storage system we should use ?
How should clients efficiently fetch data from the server ?


c) Managing user’s status


Design Summary:


Step-6: Data partitioning

Partitioning based on UserID:
Partitioning based on MessageID:


Step-7: Cache


Step-8: Load balancing


Step-9: Fault tolerance and Replication

What will happen when a chat server fails ?
Should we store multiple copies of user messages ?


Step-10: Extended Requirements

a) Group chat


b) Push notifications




← Previous: Design Dropbox

Next: Design Twitter →