Anthropic System DesignDesignFree previewFree
1-on-1 Chat System
Last asked
Problem
Design a 1-on-1 chat system (no groups, no channels). Single device per user, focused on message delivery, presence detection, offline-recipient queueing, session storage, and the tradeoff between Kafka and Redis for the message bus.
Scope
- 1-on-1 only: group chats and channels are explicitly out of scope.
- Single device per user (web).
- Messages must be delivered exactly once with reasonable ordering guarantees.
Canonical scale anchors
The reference prompt pins these numbers; back-of-envelope work should land on them within a small constant factor:
| Dimension | Value | Derivation |
|---|---|---|
| DAU | 100 M | Stated in the prompt. |
| Messages / user / day | 10 | Stated. |
| Total messages / day | 1 B | 100M × 10. |
| Average QPS | ~11,500 | 1B / 86,400 s. |
| Peak QPS | ~35,000 | ~3× average for busy hours. |
| Concurrent WebSocket connections | 10 M | 10% of DAU online at once. |
| Avg message payload | 200 B | Stated. |
| Storage / day | 200 GB | 1B × 200 B. |
| Storage / year | ~73 TB | 365 × 200 GB. |
| End-to-end delivery target | < 500 ms | Stated. |
| Availability target | 99.9%+ | Stated. |
Landing these numbers early sets up the rest of the round: 10 M concurrent sockets ÷ ~1 M / gateway ≈ 10 gateway hosts as the floor; 200 GB / day × 30 days ≈ 6 TB hot storage drives the partitioning decision for messages.
Areas the interviewer drives into
- Connection layer: WebSocket vs. long-polling; how the server tracks active connections per user.
- Presence / online detection: How does the server know when a user comes online? Heartbeats, gateway-managed presence tables in Redis.
- Offline delivery: If the recipient is offline when a message arrives, where does it queue? How is it delivered on reconnect? At-least-once vs. exactly-once.
- Session storage: Per-conversation history, pagination, retention policy.
- Kafka vs. Redis: Why pick one over the other for the message bus? Reported deep-dive on Kafka internals: partitions, consumer groups, replication, log compaction.
- Scaling: Sharding strategy (by
conversation_idoruser_id); cross-shard delivery.
Variant — thread 1183976#1
Same core topic, framed with explicit functional requirements: authenticate, establish persistent connections, receive messages in real time; support 1:1 with an explanation of how the design extends to group chat; a sent message must be persisted and delivered to an online recipient; messages must not be lost while the recipient is offline and must be retrievable after reconnect; clients must distinguish sending/delivered/failed states; preserve ordering within a conversation (explicitly scoped); support paginated chat-history queries. Discuss component boundaries (clients, edge/load-balancing layer, persistent-connection gateways, messaging services, queues/logs, storage, presence services), the complete sender→recipient data flow, gateway↔backend routing and connection ownership, message persistence and async fan-out/offline sync, duplicate sends/deliveries/reconnects/reordering/lost acks, failure cases (gateway failures, queue backlogs, temporary storage failures, cross-region network failures), and scaling/observability for latency, delivery success rate, and backlog.
Variant — thread 1184405#2
Framed for mobile + web clients, explicitly requiring multiple logged-in devices per user, at-least-once delivery with deduplication, delivered/read receipts, and horizontal scaling to a large number of concurrent long-lived connections. Asks for message IDs, idempotency keys, conversation sequence numbers and ordering, and multi-device synchronization semantics for delivered/read receipts. End-to-end encryption is explicitly out of scope.
Loading the solution…
