Design a Chat Application with Message and Thread Deletion
Design a real-time chat service whose message and thread deletions remain correct under concurrent sends and retries.
Problem statement
For this exercise, assume a real-time chat service with fixed-membership one-to-one and small group threads. Participants can create and open a thread, paginate its history, send messages, and receive updates on connected devices. A message author may globally delete that message.
A thread creator may globally delete the entire thread, making the thread and all of its messages invisible to every participant and rejecting all future sends.
The authoritative per-thread order decides a concurrent send-message versus delete-thread race: a send committed before the delete barrier may have succeeded but becomes invisible with the thread, while a send ordered after the barrier fails with THREAD_DELETED. Retried commands must return one stable outcome.
Assume 10 million daily active users, one million concurrent connections, peaks of 100,000 message sends and 5,000 deletion commands per second, and up to 100 participants in a thread. In healthy operation, durably accepted messages should reach connected recipients within 300 ms at p95.
Logical deletion should become visible to connected participants within two seconds, deleted message content should be physically purged from primary stores within 24 hours, and non-content tombstones may remain for 30 days to reject stale work.
The service should survive a single-zone failure, but it must reject new sends or deletions rather than permit two authorities for one thread. Exclude attachments, reactions, voice or video calls, full-text search, membership changes, moderation, and legal-hold behavior.
What to build
- Participants can create a fixed-membership thread, open it, and paginate its current message history.
- A participant can idempotently send a message and connected participants receive the ordered update.
- A message author can globally delete one message and all participants observe a deletion tombstone instead of its content.
- A thread creator can globally delete a thread so its history becomes invisible and concurrent or future sends resolve against one terminal delete barrier.
At scalePractice assumption
- 10 million daily active users maintain up to one million concurrent connections, with at most 100 participants in one fixed-membership thread.
- Peak traffic reaches 100,000 message sends and 5,000 message-or-thread deletion commands per second across the service.
- A durably accepted message reaches healthy connected recipients within 300 ms at p95, and a logical deletion becomes visible to connected participants within two seconds.
- Deleted content is purged from primary stores within 24 hours, non-content tombstones remain for 30 days, and per-thread writes survive a single-zone failure but fail closed without one authoritative quorum.