Design User and Item Embeddings from Long Histories
Company: Pinterest
Role: Machine Learning Engineer
Category: ML System Design
Difficulty: medium
Interview Round: Onsite
# Design User and Item Embeddings from Long Histories
Design an embedding system that represents users and visual-content items for retrieval or recommendation. User histories may contain up to 160000 events.
### Constraints & Assumptions
- Practice assumption: events include impressions, saves, clicks, hides, and timestamps.
- Items have image and metadata features; new items may have little interaction history.
- The online retrieval path has a strict latency budget and serves millions of users.
- Training examples must respect event time to avoid future leakage.
- The long-history limit is a prompt constraint, not a claim about any production implementation.
### Clarifying Questions to Ask
- Is the embedding used for candidate retrieval, ranking features, or both?
- What action and time horizon define relevance?
- How fresh must user and item representations be?
- Which privacy, retention, and deletion rules constrain history?
### Part 1: Objective and Training Data
Define examples, positives, negatives, loss, leakage controls, and offline evaluation.
#### Hints
- The way an item was exposed affects what a missing interaction means.
#### What This Part Should Cover
- Objective aligned with serving use
- Defensible negative sampling
- Time-correct splits and metrics
### Part 2: Model and Long-History Representation
Choose user and item encoders and explain how you preserve useful signals from as many as 160000 events without processing all events naively on every request.
#### Hints
- Different time scales may deserve different summaries.
- A representation can be updated incrementally.
#### What This Part Should Cover
- Multimodal item representation
- Efficient long-sequence strategy
- Freshness and cold-start behavior
### Part 3: Serving, Evaluation, and Safety
Design embedding generation, storage, nearest-neighbor retrieval, refresh, rollout, monitoring, and deletion.
#### Hints
- Training-serving skew can occur in both features and index versions.
#### What This Part Should Cover
- Versioned online architecture
- Latency and freshness trade-offs
- Online metrics, guardrails, and privacy operations
### What a Strong Answer Covers
- A clear target and unbiased evaluation strategy
- A scalable approach to very long histories
- Cold-start and multimodal item handling
- Versioned retrieval serving with monitoring and deletion guarantees
### Follow-up Questions
- How would you preserve multiple user interests in one retrieval request?
- How would you detect popularity collapse in the embedding space?
- What changes if event history must be deleted within minutes?
- When would a sequence model outperform engineered summaries enough to justify its cost?
Quick Answer: Design user and visual-item embeddings for retrieval or recommendation when histories can contain 160,000 events. Address time-correct training data, multimodal cold start, efficient long-history summaries, incremental freshness, versioned nearest-neighbor serving, privacy, and deletion.