“Design one-to-one and small-group messaging with offline delivery.”
Assume 1 million daily active users, 50 million messages per day, and group sizes capped at 100 for the initial version. Users can reconnect from multiple devices. We need durable messages, ordering within a conversation, and recoverable delivery; voice calls and large broadcast channels are out of scope.
01. Define the acknowledgments
Distinguish accepted by the server, delivered to a device, and read by a user. An accepted acknowledgment should follow the selected durable-write guarantee. A push notification is not proof that the message reached or was read by the recipient.
Give each send attempt a client-generated idempotency ID scoped to the sender and conversation. A retry with the same ID should return the original message identity rather than create another message.
Clarify encryption early. If end-to-end encryption is required, the server stores and routes ciphertext; search, previews, and moderation cannot assume access to plaintext. This walkthrough focuses on routing and durability rather than a cryptographic protocol.
02. Keep connections separate from durable state
Use gateways for persistent connections and a registry for locating connected devices. Route writes by conversation ID to an authoritative ordering partition. Authenticate the sender and verify membership before accepting the message.
Persist a monotonically increasing sequence number within each conversation. Physical timestamps alone cannot reliably order concurrent sends. If a conversation owner fails, fence the old owner before the replacement allocates more sequence numbers.
03. Make retries safe
After the durable write, asynchronously attempt delivery to connected recipients. An outbox or equivalent durable publication mechanism avoids losing delivery work between committing the message and emitting its event.
Use at-least-once delivery with recipient deduplication by message ID. Store a per-device delivered cursor and a separate user-level read position if the product needs it. Reconnecting clients request messages after their last acknowledged sequence.
Do not promise exactly-once user-visible effects merely because the transport has transactions. Kafka's design documentation explains delivery and processing guarantees within defined boundaries; clients and external side effects still need compatible handling.
Paginate history by stable cursor. A large reconnect backlog should not starve real-time messages, so bound batches and apply backpressure.
04. Estimate the dominant costs
Fifty million daily messages average about 579 writes per second before peaks and replication. If a stored envelope averages 1 KB, the raw payload is about 50 GB per day; attachments, indexes, replicas, and metadata add substantially.
Store attachments separately through an authorized file-upload flow. Route references through the conversation's permission boundary rather than embedding large binary objects in every message row.
For small groups, delivery fan-out is manageable, but the upper-bound workload depends on active group membership and devices per user. Treat broadcast-scale channels as a separate access pattern.
05. Plan for partial failure
- Lost send acknowledgment: retry with the same client ID and recover the existing message.
- Gateway failure: reconnect to another gateway and resume from the durable cursor.
- Offline recipient: preserve the message; send a bounded notification as a hint.
- Slow device: apply backpressure and switch to cursor-based catch-up rather than buffering without limit.
- Membership change: define whether history remains accessible and enforce that rule on every fetch.
Typing and presence can be ephemeral with short expiries. Their loss should not compromise durable message delivery. Monitor accepted-to-delivered delay, retry rate, cursor lag, and duplicate suppression.
06. Answer the follow-ups
“Can every conversation have global ordering?”
Ordering within a conversation is usually useful. Ordering unrelated conversations globally adds coordination without a clear user benefit. State the exact boundary.
“A user edits or deletes a message.”
Represent the change as versioned state or a sequenced event, propagate it to devices, and define retention and offline behavior. Already seen content cannot be made unseen.
Equating sent with read, trusting clocks for strict order, storing unbounded socket queues, or forgetting the database-to-event publication gap.
Sources & further reading
Apache Kafka: design and message delivery semantics for background on logs and delivery boundaries. This messaging architecture is illustrative.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.