Design a Slack-like real-time team messaging system.
Requirements:
-
Users can:
-
Create and join workspaces.
-
Create public and private channels within a workspace.
-
Send messages in channels and direct messages (DMs).
-
See message history and search messages by keyword.
-
Messages should appear in near real-time to all online participants in a channel or DM.
-
Support presence indicators (online/away) at a basic level.
-
System should support:
-
10 million registered users.
-
1 million daily active users.
-
Peak 200k concurrent connections.
Tasks:
-
Clarify and state any additional assumptions you need (e.g., file sharing scope, message size limits, retention policy).
-
Propose a high-level architecture:
-
How clients connect (e.g., WebSockets, polling).
-
Major backend services and their responsibilities (e.g., gateway, messaging service, user service, search service).
-
Data storage for users, workspaces, channels, and messages.
-
Design the data model for core entities:
-
Users, workspaces, channels, memberships, and messages.
-
Explain how you would partition/shard message data.
-
Describe how real-time messaging works end-to-end:
-
From a user sending a message to it being delivered and persisted.
-
Handling fan-out to many subscribers in a busy channel.
-
Discuss scalability:
-
How to handle 200k+ concurrent connections.
-
Horizontal scaling strategies for message processing.
-
Handling hot channels with very high message throughput.
-
Address reliability and consistency:
-
Ensuring messages are not lost (at-least-once vs exactly-once semantics).
-
Ordering guarantees within a channel.
-
Describe how you would implement search over message history:
-
Indexing strategy.
-
High-level read/write path for search.
-
Mention key trade-offs and potential future extensions (e.g., threading, reactions, file attachments).