Priority Inbox and Thread Digests for a Large Webmail Product
Machine LearningModel answerLast updated
Design a low-latency, privacy-preserving system that reorders a user's inbox by importance and attaches faithful LLM-written digests to the most important threads.
Problem
You are designing two connected features for a large consumer and enterprise webmail product:
- Priority ordering. When a user opens their mailbox, the messages are arranged so the ones that matter most appear first, tailored to that user.
- Thread digests. For threads judged important (or simply long), the system shows a short, abstractive summary that reflects the conversation context.
Constraints
- Scale and speed. Hundreds of millions of users, with millions active every day. Both ordering and digest display must finish in under 500 ms at the user-facing edge.
- Privacy. Mail is personal data. Processing must respect regional data residency rules and strict privacy expectations.
- Learning from behavior. The ranker should improve from signals such as opens, replies and deletions, without creating a feedback loop that buries important mail.
- Safety. Digests must stay faithful to the source thread, must not invent or expose sensitive details, and must not produce biased text.
What to cover
- Architecture. Outline data ingestion, the inference pipelines and the serving approach. Explain how the ranker and the generative component fit together.
- Features. Which signals matter most for priority? How do you treat long, multi-reply threads differently from short standalone messages?
- Models. Choose and justify a ranking approach (for example a two-tower retrieval-style model versus gradient-boosted trees) and a summarization approach (for example a small distilled model you host versus an external API model).
- Feedback and safety. How do you prevent a filter-bubble effect where the system only reinforces what the user already clicks? What guardrails stop personal information from leaking into generated digests?
State your scale assumptions with numbers, and discuss trade-offs and failure modes.
Hints
Hint 1
Work out the numbers first: emails per day, inbox opens per day, and the share of threads that need a digest. Use them to decide what must happen at delivery time versus at read time.
Hint 2
Keep generation off the read path: precompute a base priority score when mail arrives, use it to decide which threads get a digest, cache digests, and only do a light re-rank on inbox open.
Hint 3
Clicks are biased by display position, so log position and propensity, correct for them in training, reserve exploration slots, and pin certain categories (security alerts, manager mail) regardless of model score.
Hint 4
Treat email text as untrusted input to the summarizer: guard against prompt injection, check that each claim in the digest is supported by the source, and scan outputs for sensitive data.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing
This is really two problems: a learning-to-rank problem with biased feedback, and a constrained generation problem with strict privacy and faithfulness needs. The latency target is met mainly through architecture: do the expensive work when mail arrives, not when the inbox opens.
1. Scale assumptions
- 100M daily active users, about 40 incoming emails each per day: roughly 4B emails/day, about 46K/s average and about 150K/s at peak.
- About 10 inbox opens per user per day: 1B ranking requests/day, about 12K/s average and about 40K/s peak. Each request scores a candidate set of 50-200 recent or unread messages.
- Digests for about 10% of mail (high priority or long threads): roughly 400M generations/day, about 5K/s average.
- The p99 budget of 500 ms means generation cannot run synchronously on open.
- All processing stays in the mailbox's region, with no human access to raw content and no cross-tenant training on raw text without consent.
2. Architecture
Write path (asynchronous, on delivery)
- Mail lands on a stream. Spam and phishing filters run first.
- Feature extraction: parse headers, strip quoted replies and signatures, compute a small-encoder embedding, join sender and relationship features from the feature store.
- A cheap first-stage scorer (gradient-boosted trees) produces a base priority score stored with the message.
- If the score passes a threshold or the thread is long, enqueue a digest job. A regional GPU pool generates the digest, runs guardrails, and writes to a cache keyed by
(thread_id, last_msg_id, model_version). The cache sits with the mailbox, shares its encryption, and is purged when the thread is deleted.
Read path (on inbox open)
- Candidate generation is a simple index scan of unread/recent mail. No large retrieval is needed.
- Re-rank using only fast-changing context: time of day, device, current calendar state, items already seen this session, combined with the stored base score.
- Apply the policy layer (pinned categories and exploration slots).
- Attach digests from cache. On a miss, show the normal preview and enqueue generation.
The ranker gates the summarizer, which cuts generation volume roughly tenfold. Caching by last message ID means refreshes never regenerate.
3. Features
- Sender and relationship: historical open, reply and delete rates; org-graph distance (manager, report, peer); contact status; recency of last two-way exchange.
- Message: user in To vs Cc, recipient count, bulk-mail headers, attachments, calendar invites, detected intent (question, request, deadline), urgency terms, text embedding.
- Thread: whether the user has participated, whether the latest message asks the user something, participant count, reply velocity, age.
- Context: time since arrival, device, calendar state.
Long vs short: for long threads, compute features incrementally on the newest message plus a running thread state (participants, user replied, last ask directed at the user). Embed only the newest message, not the concatenated thread, which is costly and dominated by quoted text. Short single messages lean more on sender and content features.
4. Models
Ranking: gradient-boosted trees with a LambdaMART objective as the main ranker. The strongest signals are sparse, tabular and behavioral, inference is microseconds on CPU, and the model is easy to debug. A two-tower model (user tower, sender/message tower) is useful for producing affinity features that feed the trees, but a pure two-tower ranker underuses cross-features and context.
Labels: graded engagement. Positives from strongest to weakest: reply, forward, flag, long read, open. Negative: delete without opening. Weight by dwell time.
Position bias: higher placement alone raises open rates. Fix with inverse-propensity weighting using logged propensities, and a position feature present in training but fixed to a constant at serving.
Summarization: a distilled 3-8B model, fine-tuned on email summaries, quantized and served on in-region GPUs. External API models conflict with residency and add per-token cost at hundreds of millions of calls per day. For very long threads (beyond about 8K tokens) use incremental summarization: previous digest plus the new message yields an updated digest. Route a small tail of hard cases to a larger model, still in-region.
5. Feedback loops
Ranking only reorders; nothing is hidden, and everything is reachable chronologically.
- Hard floors: always pin manager and direct-report mail, security and payment alerts, calendar changes, and messages where the user is the sole recipient.
- Exploration: reserve one or two slots per page for epsilon-greedy or Thompson-sampled items from lower-ranked candidates, and log propensities so the data stays usable for unbiased training.
- Counterfactual evaluation: use IPS or doubly robust estimators offline, and keep a small holdout with a simple recency ordering to measure true lift.
- Monitoring: track missed-important-mail rates (for example, messages replied to after more than a day unseen) and a user-visible "why is this ranked here" control with an easy toggle to chronological order.
6. Summary safety
- Faithfulness: constrain generation to the thread, require each claim to trace to source message IDs, and run an entailment or NLI check; fall back to the plain preview if the check fails.
- PII: summaries inherit the thread's access controls and sensitivity labels. Scan output for sensitive patterns (card numbers, government IDs, credentials) and for entities absent from the source; skip or redact on sensitivity-labeled or encrypted mail.
- Prompt injection: treat email as untrusted. Place it in a delimited data channel, never follow instructions inside it, give the model no tool access, and test with adversarial emails.
- Bias and tone: red-team across names, languages and dialects, and evaluate for disparities.
- Human review: use only opt-in or synthetic data for evaluation, with eyes-off tooling.
7. Evaluation
- Ranking offline: NDCG on graded labels, calibrated with propensity correction.
- Ranking online: A/B on time-to-first-action, reply latency on important mail, and missed-important rate as a guardrail.
- Summaries: factual-consistency scores, human ratings on a consented sample, edit/dismiss rate, and latency of cache hits (target under 20 ms).
Common mistakes
- Generating summaries at read time and blowing the latency budget.
- Training on raw clicks without correcting position bias.
- Letting the model hide mail entirely rather than reordering it.
- Sending content to an external API without addressing residency.
- Embedding whole threads including quoted text.
- Ignoring prompt injection from email bodies.
Trade-offs
Pre-generation spends GPU on digests that may never be read; the score gate mitigates this. Exploration slightly lowers short-term relevance in exchange for unbiased data and less filter-bubble risk. Smaller models are cheaper and compliant but need stronger guardrails and fine-tuning.