Start by clarifying requirements and scale, then propose a content-addressable storage design where images are hashed (e.g., SHA-256) to produce a unique content ID. Use a metadata database to map user/image IDs to content IDs, and store the actual bytes once in blob storage keyed by content ID. Discuss trade-offs like hash collisions, deduplication overhead, and deletion semantics.
Pro tip: Mention that deduplication should be transparent to users and that you'd handle hash collisions by verifying byte equality before deduping. Also, consider using a two-level mapping (user_id -> image_id -> content_id) to support user-specific metadata and access control.
Ask about expected number of users, upload rate, image size, retrieval latency, and consistency needs. Confirm that deduplication is global and that users can only access their own images.
Compute a cryptographic hash (e.g., SHA-256) of the image bytes to generate a content ID. Store the image bytes once in a blob store (e.g., S3) keyed by content ID. Handle hash collisions by comparing bytes and using a secondary hash or salt if needed.
Use a relational or NoSQL database to store mappings: user_id + image_id -> content_id, along with metadata like upload time, filename, and permissions. Ensure atomic updates to avoid race conditions during concurrent uploads.
On upload: hash the image, check if content ID exists; if not, store bytes and create a new content record; then create a user-image mapping. On retrieval: look up content ID via user/image ID, then fetch bytes from blob store.
When a user deletes an image, remove their mapping. If no other mappings reference the content ID, delete the blob. Use reference counting or a background GC process to avoid orphaned blobs.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.