Lesson 8 of 16
39. Design File Storage and Sync (Google Drive / Dropbox)

39.7 How does de-duplication work?

3 min read+10 XP

The block store is content-addressed: a block's key is its SHA-256 hash.

  • Before uploading, the client asks "which of these hashes are missing?" and uploads only those. In the chapter's code, a second user saving the same file uploads nothing, and an edited file adds about one chunk, not 200 KB.
  • Across users: the same installer or PDF in a million accounts is stored once. Per-user encryption keys limit this (identical plaintext gives different ciphertext), so many services de-duplicate within an account or organisation.
  • Privacy caution: cross-user de-duplication can leak that a file already exists (an upload that "finishes instantly" reveals someone else has it). Researchers demonstrated this kind of side channel against Dropbox's early design; limiting de-duplication to a user's own data, or always uploading for small files, closes it.

Memory code: "The hash is the name: if we have it, don't send it."