Design a Community Chat Platform
Design a real-time community chat service with channels, role-based access, ordered messages, reconnect recovery, and hot-channel fanout.
Problem statement
For this exercise, assume users create or join persistent communities that contain text channels. Community owners manage membership, roles, and channel-level read or send permissions.
Authorized members can paginate message history, idempotently send text messages, and receive new messages on multiple connected devices. A reconnecting device resumes from its last acknowledged channel sequence without requiring every message to be delivered exactly once.
Each channel has one authoritative message order. A successful send returns a stable message ID and sequence, and duplicate client retries return the original outcome.
Membership or permission changes use an authoritative version: once a removal or send-deny change commits, later sends from that member must fail, while messages already committed remain in history. Real-time delivery may be at least once, so clients deduplicate by message ID and sequence.
Assume 20 million daily active users, two million concurrent connections, peaks of 200,000 message sends per second, communities with up to one million members, and a hot channel with up to 100,000 concurrently connected readers.
In healthy operation, durably accept a message within 500 milliseconds at p95 and deliver it to connected authorized members within one second at p95. Retain message history for one year and resumable delivery cursors for seven days.
Accepted messages and membership changes must survive one process or availability-zone failure. Voice or video, attachments, reactions, full-text search, bots, public discovery, moderation workflows, message editing or deletion, and active-active cross-region channel ownership are outside scope.
What to build
- A community owner can create text channels, add or remove members, assign roles, and configure channel-level read and send permissions.
- An authorized member can idempotently send a text message and paginate the authoritative ordered history of a channel.
- Connected authorized devices receive new channel messages with low latency and can acknowledge delivery progress.
- A device can reconnect with its last acknowledged channel sequence and recover retained messages without duplicating the visible conversation.
At scale
- For this exercise, assume 20 million daily active users, two million concurrent connections, and peaks of 200,000 message sends per second.
- For this exercise, support communities with up to one million members and a hot channel with up to 100,000 concurrently connected readers.
- For this exercise, durably accept a healthy authorized send within 500 milliseconds at p95 and deliver it to connected authorized members within one second at p95.
- For this exercise, retain message history for one year and resumable delivery cursors for seven days; accepted messages and membership changes survive one process or availability-zone failure.