Design Photo Storage with SHA-256 Content Deduplication and Safe Deletion
OpenAISoftware Engineer · OnsiteLast updated
Design a photo storage service that deduplicates identical uploads by their SHA-256 content hash. Cover the upload flow with server-side verification, concurrent identical uploads, deletion with reference counting and garbage collection, and the privacy risks of deduplicating across users. It tests content-addressed storage design.
Design a photo storage service: users upload photos from their phones and computers, browse their libraries, view photos at different sizes, and delete them. Many uploads are exact duplicates, for example the same photo uploaded twice from two devices, or the same image saved by many users, so the service should deduplicate identical files using their SHA-256 content hash to save storage.
Clarifying Questions
- How many users, photos per user, and uploads per day, and what is the typical photo size?
- Should deduplication work only within one user's library, or across all users?
- What metadata must be kept per photo (capture time, location, albums), and must edits keep the original?
- What are the read patterns: thumbnails in a grid, full-size views, bulk export?
- What are the privacy and deletion requirements, for example how quickly deleted photos must be gone?
Hints
Hint 1
Content is not ownership: Separate the bytes of a photo from the fact that a particular user owns a photo, and ask what each delete should remove.
Hint 2
Who computes the hash: Consider what happens if the server trusts a hash that the client computed, and what happens if two clients upload the same new bytes at the same moment.
Follow-up questions
- How would you also detect near-duplicates, such as the same photo resized or recompressed?
- A user requests deletion of all their data. How do you prove the content is gone when other users share the same bytes?
- How would you migrate billions of stored photos to a cheaper storage tier without downtime?
- How do you check that the stored bytes still match their hash years later?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.