For threat intelligence work I keep a large archive of breach and leak data. Helping a company figure out where a set of leaked credentials came from, or whether an identity shows up across multiple incidents, means having the raw material on hand. Over the years that archive grew to about 13.8 TB sitting on a NAS in my office.
And it was slow. The kind of slow that was crying out for a serious optimization pass.
Not because the data was bad or missing anything. It was all there, and all valuable. The problem was that it was just files. Thousands of folders, hundreds of thousands of files, every breach in whatever shape it happened to leak in: SQL dumps here, JSON exports there, giant email:password combo lists, CSVs, text files split into a thousand pieces. If someone asked me “has this phone number ever appeared in a breach you have?”, my honest answer was “probably, somewhere, give me a bit.” Everything I needed was sitting right there in the archive. Actually reaching it was the bottleneck.
So I decided to fix it: turn the pile into something I could query in milliseconds. Here’s how that went.
First, know what you actually have
Before indexing anything, I needed a map. I walked the whole archive and built a catalog: every dataset, its size, its file formats, roughly how many records, what kinds of fields it held (emails, passwords, phones, names, usernames, national IDs), and what region or language it covered.
The numbers that came back set the tone for the whole project:
- 936 datasets
- 340,938 individual files
- ~52 billion records
- 9.83 TB of actually-indexable data (the rest being archives, binaries, and duplicates)
That last point was its own small win. An old script had split large files into chunks but kept the originals too, leaving 3.6 TB of pure duplicate sitting on the drive. Cataloging surfaced it, and clearing it was the easiest terabyte I ever got back.
The catalog itself became a living HTML page I can search and filter, and regenerate whenever I add data. Before you can make something fast, you have to know its shape.
Why not just grep it
The obvious first instinct is “just search the files when you need to.” I had actually set up a full-text index over part of the archive early on. A single search against it, over the network, took more than 25 minutes. For a corpus this size, brute force is a non-starter. You cannot read 10 TB to answer one question about one phone number.
The realization that unlocked everything: I don’t need to search the data. I need to search the identifiers in the data, and I need a way to jump straight back to the original record once I find one.
The identifier index
So that’s what I built. Instead of indexing every word, the system reads each dataset, understands its format, and pulls out only the high-value identifiers:
- email addresses
- phone numbers
- names
- usernames
- national IDs (US SSNs, Chinese resident-ID numbers)
- social handles (Facebook, LinkedIn, QQ, WeChat, Twitter)
Each one gets normalized so that the same identity matches no matter how it was written, then stored in a lookup that points back to the exact byte where that record lives in the original file.
Two design choices made this work at 52-billion-record scale.
Normalization that reflects reality. Phone numbers are keyed on their last ten digits, so +1 415 555 0123, 4155550123, and 014155550123 all collide on purpose. Chinese names are matched both in characters and in pinyin, so a Han-script name in one breach can line up with a romanized name in another. Social handles are prefixed by network (qq:, fb:, li:) so they never cross-match.
Pointers, not copies. The index does not store the records. It stores, for each identifier, a single 64-bit number that encodes which file the record is in and the byte offset where it starts. The raw 10 TB never moves off the NAS. The index that sits on top of it is a fraction of the size, and a lookup is a binary search into sorted arrays followed by one seek into the original file. When a result comes back, the system re-reads that exact record and re-derives its identifiers, which doubles as verification: if a hash collision ever points at the wrong record, it gets dropped before you ever see it.
The identifiers are sharded 256 ways by a hash prefix, each shard a pair of sorted arrays. Finding every record for a given email is a couple of binary searches and a handful of disk seeks. Milliseconds, not minutes.
The parts nobody puts in the diagram
Building this on real breach data, on one consumer machine (a desktop with 64 GB of RAM, 32 threads, and the archive living on a NAS over a saturated network link), produced the usual collection of scars.
The regex that ate ten hours. The extractor parses SQL dumps by pulling values out of INSERT statements. A pattern I had “optimized” contained a classic catastrophic-backtracking trap: on a malformed quoted string inside one of the giant SQL breaches, the regular expression engine would spin forever on a single record. One bad row and a worker process pinned a CPU core at 100% producing nothing. Several of the biggest files hit it at once and the whole run wedged. The tell was subtle: every process looked busy, but not one byte of new index was being written. Once I understood it, the fix was one line (a possessive quantifier that can’t backtrack), but it cost a chunk of a day first.
The reboot at 97%. The final step folds all the extracted identifiers into the sorted shards. During one of these merges, nearly a full day into a run, the machine rebooted on its own. It came back with the merge interrupted at shard 250 of 256. Because every file’s “done” state is committed as it finishes, and because the merge is written to be idempotent (re-running it can only ever produce the same sorted, de-duplicated result), recovery was a matter of folding the last six shards and nothing was lost. Building for resumability is not optional at this scale. Something will interrupt a multi-day job.
Everything is a different format. Real breaches do not agree on anything. One file is UTF-16 with a byte-order mark, the next is GB18030 Chinese text, the next is a Mexican voter database in an ancient DBF format, the next is twenty-five billion lines of email:password. The extractor has to sniff each file and adapt. Most of the engineering time went here, in the unglamorous business of reading other people’s messes.
Where it landed
The archive is now a searchable corpus. 52 billion records across 936 datasets, every email, phone, name, username, national ID, and social handle indexed, pointing back to its exact source record, answering lookups in milliseconds instead of hours.
“Has this phone number appeared in a breach I have?” went from a multi-hour maybe to an instant yes-or-no with the receipts attached.
That alone was worth the build. But a fast index still has a catch: you have to know what to ask it, and you have to do the cross-referencing by hand. A phone gives you an email, the email gives you a username, the username shows up in three more datasets, and you’re ten manual lookups deep building a picture of one person.
That’s tedious work. It’s also exactly the kind of tedious work a language model is good at driving, if you give it the right tools. So the next thing I built was a way to hand this whole corpus to an AI and let it do the pivoting itself. That’s the next post.