BetterSWE DigestWhat is BetterSWE?

Deep Dive · Issue 16

Before You Hash, Define "Duplicate"

Your definition of what counts as a duplicate cascades into every algorithm, data structure, and cost in your dedup pipeline.

Spectrum of deduplication definitions from exact to near-duplicate to sub-file

The framing question

What counts as a duplicate?

Spectrum of deduplication definitions from exact to near-duplicate to sub-file

Every deduplication system starts with one decision: what counts as a duplicate? The spectrum runs from byte-identical copies through near-duplicates to sub-file redundancy, each needing a different mechanism family.

Three definitions of 'duplicate,' three algorithm families.

Exact dedup via SHA-256 is cheap and precise: hash each document, store it in a lookup set, discard matches. One billion fingerprints costs ~32 GB of memory. But it misses anything reformatted, re-encoded, or edited by a single character.

The normalization prerequisite

Raw documents from different sources may encode identical content with different whitespace, Unicode forms (NFC vs NFD), or HTML entities. Standard normalizations like lowercasing and collapsing whitespace catch more variants but risk merging materially distinct documents.

Your definition of 'duplicate' is the first architectural decision. Everything downstream is a consequence.

The mechanism

Why fixed-size chunking fails

Content-defined chunking with a rolling hash scanning byte by byte

Fixed-size chunking splits a file into blocks at every N bytes. Insert one byte at the beginning and every downstream boundary shifts, so the system detects zero duplicates. This is the boundary-shift problem.

Content-Defined Chunking (CDC) solves this by setting boundaries based on content, not position. A rolling hash (originally a Rabin fingerprint) slides over the byte stream byte-by-byte. A cut-point is declared when the hash satisfies:

H(window) mod 2k=0⇒chunk boundaryH(\text{window}) \bmod 2^k = 0 \quad \Rightarrow \quad \text{chunk boundary}
k governs expected average chunk size (2^k bytes). Larger k means fewer, bigger chunks.

Because the cut condition depends on window content, not file position, inserting or deleting bytes only shifts the nearest boundary. Everything downstream stays aligned. CDC detects 10-20% more redundancy than fixed-size chunking.

The numbers

Chunk size: the one knob that controls everything

Chunk size as the master parameter controlling four cost dimensions

Average chunk size ties together four competing cost dimensions. Smaller chunks find more redundancy but produce more index entries and hashing work. Larger chunks mean less metadata overhead but lower dedup ratios.

Smaller chunks

More dedup, more CPU, bigger index

Larger chunks

Less overhead, less dedup, smaller index

The C4 dataset stripped ~70% of raw text from Common Crawl by removing repeated 3-sentence spans. The Pile carried ~30% duplication, and GitHub repositories can exceed 50% redundancy from forks and boilerplate.

Storage and speed at scale

Microsoft reports ~50% redundancy in primary storage, EMC reports ~85% in secondary, with chunk-level dedup achieving up to 83% space savings. With fast chunking like FastCDC, the cryptographic hash becomes the primary CPU cost, not the rolling hash. FastCDC runs ~10x faster than Rabin-based CDC at nearly the same dedup ratio.

Average chunk size is the single knob that simultaneously controls CPU, memory, network, and storage.
The CDC algorithm zoo: Rabin, Gear, FastCDC, BFBC

CDC algorithms fall into three families. Hash-based (Rabin 1981, Buzhash 1997, Gear 2014) use polynomial or shift-and-lookup rolling hashes. Local extrema (AE, RAM, MII) place boundaries at local minima or maxima in a discrete window. Frequency-based (BFBC) uses byte-pair frequency estimation, running 10x faster than basic sliding window.

FastCDC (2016) combines three tricks: an enhanced Gear hash with padded zero bits, sub-minimum cut-point skipping, and normalized chunking that constrains chunk-size distribution to a target range like 8-16 KB. Vectorized CDC (2025) shifts to hashless approaches using CPU vector instructions, achieving 8-26x throughput gains.

Where it breaks

Your chunk boundaries are an attack surface

Security attack exploiting observable chunk boundaries

CDC boundaries create a side channel. Rolling hash-based chunking is exploitable because chunk boundaries are publicly observable. Attackers can extract hidden parameters like the prime modulus, multipliers, or coefficient maps.

Chunk boundaries leak algorithm internals, which enable content fingerprinting.

Concrete parameter extraction has been demonstrated against Tarsnap, Borg, and Restic. Protocol-agnostic attacks can fingerprint files or extract sensitive portions purely from chunk size distribution analysis, without breaking any encryption.

Hardening the boundary

The fixes: replace simple rolling hashes with cryptographically robust PRFs like HMAC, enlarge keyspaces (Buzhash to 64-bit), and introduce randomized chunking strategies so boundaries are not deterministic from content alone. Making the definition of "duplicate" unobservable is a constraint that shapes the chunking algorithm itself.

Wrap-up

The definition shapes the system

Why it matters

The leap from byte-identical to content-defined changes the entire system: different costs, different data structures, and a different security posture. Teams building dedup pipelines routinely underestimate how much the initial framing decision constrains everything that follows, from memory budgets to attack surface.

The short version

  • **Define "duplicate" first.** Byte-identical, near-duplicate, and sub-file chunking each require a different algorithm family and cost profile.
  • Exact hashing (SHA-256) is cheap but brittle: one changed byte defeats it. **Normalization** is the hidden prerequisite that determines recall.
  • **Content-Defined Chunking** sets boundaries by content, detecting 10-20% more redundancy than fixed-size chunking.
  • **Average chunk size** is the master knob controlling CPU, memory, network, and storage costs simultaneously.
  • CDC chunk boundaries are an **attack surface**: observable sizes can leak algorithm parameters and enable content fingerprinting against Tarsnap, Borg, and Restic.

Sources

  1. 1.What is Document Deduplication?
  2. 2.Deduplication: Exact, Near-Duplicate, and Substring Methods - Interactive
  3. 6.Content-Defined Chunking
  4. 7.FastCDC: a Fast and Efficient Content-Defined Chunking ...
  5. 8.A Thorough Investigation of Content-Defined Chunking ...
  6. 9.Data Deduplication System Based on Content-Defined Chunking Using Bytes Pair Frequency Occurrence
  7. 10.Deduplication in Action