KatInterview

Design a Reverse-Image Search Index at Scale

System DesignModel answer
MediumModel answerSystem Designsystem designstorageindexing

Last updated

Design a system that accepts an image query and returns visually similar images from a corpus of billions, covering storage, indexing, and retrieval trade-offs.

Reverse-Image Search Index

Background

You are joining a team building a reverse-image search feature for a large media platform. Users can upload or paste any image and instantly receive the most visually similar images from a catalog of 5 billion photos. The catalog grows by roughly 10 million new images per day.

Functional Requirements

  1. Query: Given an image (upload or URL), return the top-K (default K=20) most visually similar images.
  2. Ingest: New images added to the catalog are searchable within 5 minutes.
  3. Delete: An image removed from the catalog (e.g., copyright takedown) must stop appearing in results within 1 hour.

Non-Functional Requirements

  • Query latency: p99 < 300 ms end-to-end (including embedding generation).
  • Write throughput: sustain ~115 images/second on average with 3× burst headroom (~350/s).
  • Availability: 99.9% uptime for queries; ingest may tolerate brief degradation.
  • The catalog is read-heavy: roughly 5,000 queries per second at peak.

Out of Scope

  • Training the image embedding model itself.
  • Content moderation or deduplication logic.
  • User authentication.

What is Expected

Walk the interviewer through:

  1. API design (ingest, query, delete endpoints).
  2. Data model — what you store and where.
  3. Architecture — the end-to-end pipeline from image upload to search result.
  4. Indexing deep dive — how approximate nearest neighbor (ANN) search works here and which data structure / algorithm you'd choose.
  5. Trade-offs — at least two meaningful decisions with pros/cons.
  6. Failure modes — what breaks first and how you mitigate it.

Hints

Hint 1

Start by estimating the storage footprint: if each embedding is a 512-dimensional float32 vector, how many bytes is that for 5 billion images? Does it fit in RAM?

Hint 2

Think about why exact nearest-neighbor search (brute-force dot product over 5B vectors) is infeasible at p99 < 300 ms, and what ANN index structures (HNSW, IVF, LSH) trade off recall for speed.

Hint 3

For the freshness requirement (searchable within 5 minutes), consider whether your ANN index supports online inserts or requires periodic rebuilds, and what that means for your architecture.