MLCrack

    ML SYSTEM DESIGN (DEEP DIVES) · INTERVIEW QUESTION

    Design a visual search system (Pinterest-style) over 5B+ images with sub-500ms p95 latency.

    🔴 advanced · Vector Search / Multimodal

    Hint: Embedding model + ANN + reranker. Discuss sharded HNSW/IVF-PQ, hard-negative mining, re-indexing strategy.

    Answer

    1. Problem Formulation

    "Find visually similar pins" — Pinterest's classic problem.

    Clarifying questions:

    • User intent? Two surfaces: (a) "shop the look" — user taps a region of a pin and we find visually-related products; (b) "more like this" — find similar pins to one the user saved. Same backbone, different ranking.
    • Scale? ~5B pins indexed, ~500M MAU, ~200M visual searches/day. p95 latency ≤ 500 ms end-to-end (visual search is more latency-tolerant than feed).
    • Quality definition? Top result should be visually similar AND topically relevant AND shoppable when appropriate. "Visually similar" alone returns near-duplicates, which is boring.
    • Constraints? Image rights and policy filters (no NSFW, no hate symbols), shoppable-product attribution to merchants.

    Why ML? Visual similarity is not expressible in features humans hand-design at this scale. Pre-deep-learning systems used SIFT/HOG and topped out at ~30% top-1 accuracy on visual search; learned embeddings reach ~85%.

    ML framing: image (or image-region) → embedding → ANN search. Plus a ranker on top of ANN results. Optionally cross-modal (image ↔ text) for the shopping intent.

    2. Metrics

    Offline:

    • Recall@K on a held-out set of (query, known-relevant-pin) pairs.
    • NDCG@K with human-judged relevance ratings on a sampled eval set.
    • Embedding quality probes: downstream tasks (category classification, attribute prediction) — a good embedding transfers well.

    Online:

    • Save rate on results (the primary positive signal on Pinterest).
    • Tap-through rate, outbound click rate (for shopping), long-dwell rate.
    • Guardrails: irrelevant report rate, near-duplicate rate (should be low — duplicates are visual noise).

    Trade-off: larger embeddings (1024-d) improve recall but cost more in storage and ANN latency. Quantization (PQ/SQ) trades a few points of recall for 10× storage and speed gains.

    This is the opening of a longer walkthrough. Read the full answer in the topic explorer, free.

    Likely follow-up: How do you re-index 5B vectors when you upgrade the embedding model?