Google SD

Design Google Photos Duplicate Detection

Find near-duplicate and burst photos — perceptual hashing, clustering, and user-facing suggestions.

Interview tip Pipeline: hash → bucket candidates → ML refine. Mention privacy (on-device vs cloud) and scale of billions of images.

① Functional requirements

  • Detect visually similar photos and videos
  • Group bursts into stacks
  • Suggest "best" photo to keep
  • On-upload processing
  • User can dismiss suggestions
  • Works across resolutions and crops

② Non-functional requirements

  • Process upload within seconds
  • Billions of photos corpus
  • Low false positive on faces
  • Privacy — user data isolated

③ Back-of-the-envelope scale

Assumptions
  • 5B photos
  • 50M uploads/day
  • pHash 64-bit per image

④ High-level architecture

Photos Duplicate
Upload
Perceptual hash worker
Similarity index
Cluster + rank best

⑤ Data flow & execution path

Duplicate pipeline
Generate pHashHamming bucketML verifySuggest stack
On-device hash optional
Embeddings for semantic similarity

⑥ API & interfaces

Endpoint / flowPurposeNotes
POST /photosUpload triggers pipelineasync
GET /stacksDuplicate groupsuser scoped

⑦ Data model & storage

Domain-specific entities sharded by user_id or geographic key.
StoreWhatWhy
Distributed storePrimary dataSharded for scale
Kafka / Pub/SubEvent logAsync pipelines
Object storeMedia / blobsGCS-style durability

⑧ Deep dive — core components

Perceptual hash bucketing

Hamming distance ≤ 5 → candidate pair; CNN embedding for final merge.

Best photo selection

Score sharpness, faces smiling, exposure — lightweight on-device model.

⑨ Trade-offs & alternatives

DecisionOption AOption BPick when
Where computeCloudOn-deviceOn-device privacy; cloud more accurate
IndexLSHBrute on recentRecent window brute; archive LSH

⑩ 45-minute interview script

  1. 0–5 min: Requirements + Google-scale assumptions
  2. 5–12 min: Back-of-envelope QPS and storage
  3. 12–22 min: Architecture diagram
  4. 22–35 min: Deep dive on hot path
  5. 35–42 min: Failure modes and trade-offs

⑪ Likely follow-up questions

QuestionShort answer
How roll out globally?Regional cells + gradual feature rollout

⑫ Revision checklist

  • pHash
  • Hamming threshold
  • ML second stage
  • Privacy boundary
  • User dismiss
googlephotosperceptual-hash