The interview problem
Build conversation grouping for a multi-tenant support inbox receiving one million emails per day. Replies may arrive before their parents, delivery notifications may repeat and unrelated messages may have the same subject. Preserve messages and avoid exposing another mailbox's private conversation through a forged reference.
Original system-design practice, not a reported company interview. Scenarios and capacities are hypothetical. Primary protocol reference retrieved September 27, 2026; interview date not applicable.
1. Separate delivery, message and conversation identity
A delivery event identifies a provider notification or received copy. A message record identifies the stored email. A conversation groups related messages for display. These are not interchangeable identifiers. One message can reach multiple mailboxes, and two distinct emails can incorrectly reuse a Message-ID.
RFC 5322 defines Message-ID, In-Reply-To and References fields. Use them as relationship evidence, not authentication. Parse them with a standards-aware parser, retain the raw headers and avoid ad hoc normalization that collapses distinct identifiers. Sender-supplied dates and subjects are also untrusted claims.
Scope relationship lookup to the tenant and authorized mailbox collection. A matching external identifier must never grant access to another mailbox. Conversation membership is a display relationship; authorization remains attached to messages and attachments. A group can contain messages with different visibility without making all of them visible to every participant. Derive snippets, counts, participant lists and last-activity timestamps from the viewer's authorized projection too; filtering only message bodies still leaks metadata.
2. Store evidence before deriving groups
provider delivery → durable raw message + receipt identity
↓
bounded MIME/header parser
↓
message record + reference candidate edges
↓
scoped relationship resolver and conflicts
↓
versioned conversation projection → inbox UIPersist the raw message and a durable receipt before acknowledging ingestion. If object storage and metadata are separate, use a staged object plus transactional metadata/outbox and reconcile orphan objects. Do not acknowledge a receipt that exists only in worker memory.
Deduplicate retried provider notifications with a documented provider event identity scoped to the account. A body hash alone can collapse two legitimate repeated messages. A repeated Message-ID with conflicting content should create an ambiguity record, preserving both receipts and content rather than overwriting the first email.
Store parsed reference candidates separately from accepted grouping edges. Include the matching rule, parser version, evidence and override history. This makes it possible to repair an incorrect merge. A permanently destructive union of all matching identifiers makes later splits unnecessarily difficult.
3. Resolve out-of-order replies
Suppose message C arrives with In-Reply-To=B and References containing A and B. Neither A nor B is stored. Create C and unresolved scoped reference nodes for the missing identifiers. Show C in a provisional conversation; a placeholder is not proof that its referenced message exists or is accessible.
Next, B arrives referencing A. Resolve the B placeholder only if its identity is unambiguous and authorized for this grouping scope. Record B's relationship to A and associate C with the resulting conversation. Finally A arrives; the chain becomes A→B→C without rewriting the raw messages. A duplicate delivery notification for C records no second visible message under the provider's deduplication contract.
An unrelated D with subject “Re: Invoice” and no references stays separate, even if A had subject “Invoice.” Subject normalization can suggest a possible relationship for review, but a common subject is weak evidence. Conversely, a reply that changes subject can still belong to the chain when its explicit references are valid.
Conflicting parents, multiple reference candidates, reused identifiers and cycles require explicit policy. Preserve evidence and prefer an unresolved or separately displayed message over an irreversible merge. Bound reference count, graph depth and parser work so a hostile header cannot force unbounded traversal.
4. Make regrouping deterministic and reversible
When two provisional groups become connected by accepted evidence, choose a stable canonical conversation identity and retain aliases from old identifiers. Update membership through a serialized transaction or versioned compare-and-swap. Concurrent workers must not independently publish incompatible parents or create alias loops.
Keep internal message IDs stable while conversation projections change. When a merged conversation is later split, its old alias may be ambiguous: show an authorized selection or use a message-anchored link rather than silently selecting the wrong branch. A user can open an old conversation link through its alias, but the server must recheck access on the resolved messages. If a later conflict requires a split, reconstruct groups from accepted edges and explicit user overrides. Avoid letting a delayed automatic job undo a newer manual split; compare projection and override versions at publication.
Sort display using a documented policy combining reply structure and available timestamps, with a stable internal-ID tie-breaker. Received time is trustworthy only for when this service received the message, not when the author sent it. A malicious or broken Date header must not move a conversation infinitely into the future or suppress newer arrivals.
5. Do not turn a reference into a disclosure
An attacker may guess or obtain a Message-ID and send a message claiming to reply to it. That can justify a candidate edge, never permission to reveal the target's body, recipients or attachments. Apply mailbox authorization before searching relationship candidates and again when rendering or generating a reply.
Keep delivery-envelope and blind-recipient metadata distinct from the displayed recipient list. Grouping copies must not reveal a hidden recipient from one copy to readers of another. A reply-all action needs explicit recipient construction from the user's authorized copy, not a union of all addresses ever observed in the conversation.
For sender-visible support portals, use a separately authorized ticket association. Do not expose historical staff notes because an incoming email shares a subject or reference. Automated replies must use the same access boundary as the UI; a correct UI filter cannot compensate for a background summarizer reading private messages.
6. Size storage and asynchronous repair
One million emails per day averages about 11.57 per second. A 20-times peak is about 231.48 per second. At 50 KB of raw data per message, excluding large attachments, ingestion is 50 GB per day or 1.5 TB over 30 days in decimal units before replication. Attachment size distributions need a separate budget; averages alone hide large-message pressure.
If each message stores at most 20 accepted or retained reference candidates at 100 bytes each, relationship metadata can add up to 2 GB per day before indexes and database overhead. Bounds are operational policy: preserve raw headers so a later authorized repair can inspect truncated evidence.
Keep ingestion separate from expensive conversation repair. A resolver processing 1,000 messages per second takes 1,000 seconds, or 16 minutes 40 seconds, to replay a one-million-message batch with no new arrivals. If the same queue continues receiving 200 per second, net drain is 800 and clearing a one-million-message backlog takes 1,250 seconds, or 20 minutes 50 seconds. These hypothetical rates require benchmarking on pathological reference graphs as well as ordinary messages.
7. Failure analysis and self-review
Test child-before-parent delivery, conflicting Message-IDs, missing headers, cycles, duplicate notifications, two simultaneous merges, manual split followed by an old worker result, cross-tenant references and hidden-recipient copies. Measure unresolved-edge age, grouping corrections, duplicates and ingestion lag; a low unresolved rate achieved by over-merging is not success.
Trade-offs: Conservative grouping leaves more separate conversations but reduces false merges. Reversible projections require more evidence storage and version management. Strict authorization may produce different visible thread shapes for different users, which is preferable to leaking messages.
Follow-ups: Is Message-ID a trusted identity credential? No. Does identical subject imply one conversation? No. Does a missing parent justify dropping a reply? No. Can a merge union permissions? No. Can one body hash safely deduplicate every delivery? Not without a stronger delivery contract.
Score 0–2 each for identity separation, out-of-order resolution, reversible concurrency, authorization and bounded processing. A strong answer treats threading as an evidence-based projection rather than a permission mechanism.
Sources and next steps
- RFC 5322: Internet Message Format — October 2008; identification headers, dates and recipient fields.
The grouping policies, architecture, failure traces and sizing are original design proposals. Continue with conversation history for application-owned message storage and synchronization.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.