KatInterview

Exact-Match File Deduplication at Petabyte Scale

System DesignModel answer
MediumModel answerSystem Designsystem-designdeduplicationhashing

Last updated

Design a service that finds byte-identical files across billions of stored objects and lets clients check for existing content before uploading, while keeping network transfer low.

Exact-Match File Deduplication at Petabyte Scale

You are designing a component of a large cloud storage platform that holds billions of files and petabytes of data. Two files are duplicates if their contents are identical byte for byte, regardless of file name, folder, or owner.

The service has to work in two modes:

  • Online: before a client uploads a file, it can ask whether identical content is already stored, so the upload can be skipped.
  • Offline: a periodic batch scan locates duplicates already sitting in storage and reconciles the online index.

Requirements

Functional

  1. Detect every group of exact duplicates across the distributed store.
  2. Expose an API that answers "does this content already exist?" before an upload.
  3. Handle millions of new files per day.

Non-functional

  1. The existence check must have low latency.
  2. The duplicate index must be highly available.
  3. The design must stay correct even if two different files produce the same hash.

Constraints

  • File sizes range from a few KB to hundreds of GB.
  • Keep network I/O low. Avoid pulling whole files across the network just to compare them.

What to cover

  1. The high-level architecture and the data flow when a file is ingested.
  2. The schema of the metadata index.
  3. How the design treats small, medium and very large files efficiently.
  4. How you would detect and handle a hash collision.

State your own scale assumptions up front and use them to justify your choices.

Hints

Hint 1

Size the problem first. Work out how big an index of one digest plus metadata per file would be. If it fits in a sharded key-value store, the hard part lies elsewhere: hashing data without moving it, and staying correct under concurrency.

Hint 2

Order comparisons from cheapest to most expensive: file size from metadata, then a hash of a few sampled byte ranges, then a full-content hash only for files that are still candidates. Run the hashing next to the disks and send back only digests.

Hint 3

Think about what can go wrong beyond collisions: two uploaders racing with the same new content, a client that lies about its hash, someone who learns a hash and claims a file they never had, and deleting a blob that another file still references.