In this chapter we explore the design of a chat system. Almost everyone uses a chat app. Figure 12-1 shows some of the most popular apps in the marketplace. A chat app performs…
- 12.01Design a chat systemIn this chapter we explore the design of a chat system. Almost everyone uses a chat app. Figure 12-1 shows some of the most popular apps in the marketplace. A chat app performs…
- 12.02Step 1 - Understand the problem and establish design scopeIt is vital to agree on the type of chat app to design. In the marketplace, there are one-on-one chat apps like Facebook Messenger, WeChat, and WhatsApp, office chat apps that…
- 12.03Step 2 - Propose high-level design and get buy-inTo develop a high-quality design, we should have a basic knowledge of how clients and servers communicate. In a chat system, clients can be either mobile applications or web…
- 12.04PollingAs shown in Figure 12-3, polling is a technique that the client periodically asks the server if there are messages available. Depending on polling frequency, polling could be…
- 12.05Long pollingBecause polling could be inefficient, the next progression is long polling (Figure 12-4). In long polling, a client holds the connection open until there are actually new…
- 12.06WebSocketWebSocket is the most common solution for sending asynchronous updates from server to client. Figure 12-5 shows how it works. WebSocket connection is initiated by the client.…
- 12.07High-level designJust now we mentioned that WebSocket was chosen as the main communication protocol between the client and server for its bidirectional communication, it is important to note…
- 12.08Data modelsJust now, we talked about using key-value stores as our storage layer. The most important data is message data. Let us take a close look. Message table for 1 on 1 chat Figure…
- 12.09Step 3 - Design deep diveIn a system design interview, usually you are expected to dive deep into some of the components in the high-level design. For the chat system, service discovery, messaging…
- 12.10Service discoveryThe primary role of service discovery is to recommend the best chat server for a client based on the criteria like geographical location, server capacity, etc. Apache Zookeeper…
- 12.11Message flowsIt is interesting to understand the end-to-end flow of a chat system. In this section, we will explore 1 on 1 chat flow, message synchronization across multiple devices and…
- 12.12Online presenceAn online presence indicator is an essential feature of many chat applications. Usually, you can see a green dot next to a user’s profile picture or username. This section…
- 12.13Step 4 - Wrap upIn this chapter, we presented a chat system architecture that supports both 1-to-1 chat and small group chat. WebSocket is used for real-time communication between the client…
References
Step 4 - Wrap up
- Erlang at Facebook: https://www.erlangfactory.com/upload/presentations/31/EugeneLetuchy-ErlangatFacebook.pdf
- Messenger and WhatsApp process 60 billion messages a day: https://www.theverge.com/2016/4/12/11415198/facebook-messenger-whatsapp-numbermessages-vs-sms-f8-2016
- Long tail: https://en.wikipedia.org/wiki/Long_tail
- The Underlying Technology of Messages: https://www.facebook.com/notes/facebookengineering/the-underlying-technology-of-messages/454991608919/
- How Discord Stores Billions of Messages: https://blog.discordapp.com/how-discordstores-billions-of-messages-7fa6ec7ee4c7
- Announcing Snowflake: https://blog.twitter.com/engineering/en_us/a/2010/announcingsnowflake.html
- Apache ZooKeeper: https://zookeeper.apache.org/
- From nothing: the evolution of WeChat background system (Article in Chinese): https://www.infoq.cn/article/the-road-of-the-growth-weixin-background
- End-to-end encryption: https://faq.whatsapp.com/en/android/28030015/
- Flannel: An Application-Level Edge Cache to Make Slack Scale: https://slack.engineering/flannel-an-application-level-edge-cache-to-make-slack-scaleb8a6400e2f6b