KatInterview

Content-Addressed Photo Service with Cross-User Deduplication

System DesignModel answer
MediumModel answerSystem Designstoragededuplicationdistributed-systems

Last updated

Design a service where users upload, view, and remove photos, storing each unique content blob once using its hash as the key.

You're building a photo service that lets users upload, retrieve, and remove their photos. To save storage costs, the system should avoid keeping multiple copies of identical content: whenever two photos have matching SHA-256 hashes, only one copy of the actual bytes should be stored.

Requirements

Your design should address:

  • How users upload photos and how the system detects duplicates
  • How users retrieve their photos
  • How deletion works when multiple users might reference the same underlying content
  • What happens when one user uploads the same content another user already has
  • Data modeling and storage architecture
  • Consistency and concurrency challenges

Constraints

  • Two photos are considered identical only if their SHA-256 hashes match exactly; any modification produces different content
  • You may assume reasonable scale (state your assumptions)
  • Focus on correctness, then discuss scalability

Discussion Points

Consider addressing:

  • Whether deduplication should happen across all users or be scoped per-user
  • Authorization model: who can access which photos
  • Garbage collection strategy for unreferenced content
  • Race conditions during concurrent operations
  • Privacy implications of shared storage
  • Client-side optimizations

Hints

Hint 1

Separate the concept of user ownership from physical storage

Hint 2

Reference counting isn't enough when operations are concurrent

Hint 3

Hashing the same content twice reveals information across user boundaries