Skip to content
Writing

Case study

Thirteen billion URLs, one primary key

A case study: how a 1.1 TB archive of factory repair manuals, 13.7 billion URLs once flattened, became 70,749 Postgres rows that an AI agent searches in about 300 ms. And why the obvious table, one row per URL, was the first thing we threw away.

A mechanic asks an AI assistant: "2016 Charger Pursuit, 3.6 litre: how do I replace the coolant pump?" The factory procedure exists, in a publicly distributed archive of service manuals covering almost every car sold in North America since 1960. Search has to land on the right page of the right manual in about a third of a second, so the assistant can show the page and its diagrams.

The archive was 1.1 TB, in a binary format nobody had tooling for. Flattened out, it became 13.7 billion URLs.

2 billionsearchable documentsa page at one place in one manual
19×smaller than one row per document~1.3 TB → 69 GB
~0.3 sper searchone primary-key read
4%of returned pages are for the wrong vehicledown from 60%
Role
Lead engineer. I reverse-engineered the archive format and built the extraction and deduplication pipeline, the storage design, the ranking index and the agent's tools.
Timeline
Jan – Oct 2026; pipeline finished May 2026, served from Postgres since Aug 2026
Team
Five engineers
Scale
279,988 vehicles · 65 makes · 52.6M pages · 13.2M images
Stack
Python, Postgres, Arrow + Parquet, zstd, numpy, SQLite, Kubernetes, object storage
Terms used in this post
  • Document: one page at one place in one manual's table of contents. It's the unit search returns.
  • Primary key: the column a table is looked up by. Reading one row by its key is the fastest thing Postgres does.
  • Embedding: a list of numbers that captures what a phrase means, so "water pump" and "coolant pump" land close together.
  • Keyword match (BM25): the classic search-engine score for how well the words match.
  • Arrow, zstd: a compact column-by-column data format, and the compressor we used on it. The number after zstd is its compression level.
  • try_these: a field in the search tool's reply that lists the manual's own words for what the agent asked about.

The problem: billions of addresses, one question at a time

The archive is organised like a filing cabinet per vehicle. Each of 279,988 vehicles has a deep table of contents, from section and system down to component and operation, and each entry points at a page. List every entry for every vehicle and you get 13.7 billion URLs. Yet the archive only holds 52.6 million distinct pages, because the same page is reused across trims, years and sections.

That gives a chain of counts that are easy to confuse:

A chain of counts: a 1.1 TB archive with 52.6 million pages; 280 thousand vehicles; 13.7 billion URLs, one per table-of-contents entry; 70,750 manuals after merging identical trims; 2.03 billion documents, each a page at one place in one manual; 70,749 Postgres rows, one per manual.
Fig. 01What each number means. In this post, a document is one page at one place in one manual's table of contents. That's the thing search has to find.

Two facts about how the assistant asks questions decided the design:

  1. Every question is about one vehicle, so only one manual is ever in play. The average manual has about 28,700 documents and the largest has 390,000. No question ever needs two billion.
  2. The agent asks in its own words, such as "water pump", "brake job" or "AC not cold", while the manuals use their own: "Coolant Pump", "Disc Brake System", "HVAC". Search has to bridge that gap.

1 · Collapse 13.7 billion URLs into 2 billion documents

Most trims of a car share a manual. Fingerprinting each vehicle's full list of URLs and grouping identical fingerprints collapsed 279,988 vehicles into 70,750 manuals, a 4× reduction. Walking one vehicle per manual and keeping each page once per place in its table of contents left 2.03 billion documents.

The obvious tools broke here. DuckDB's global deduplication ran a 40 GB machine out of memory twice. What shipped is plain Python that streams the data and never uses more than 300 MB. It's only correct because of two properties we checked first instead of assuming: every manual sits entirely inside one data shard, and the rows arrive grouped by manual. With both true, deduplicating two billion rows at once becomes deduplicating one manual at a time.

Under the hood: reading a format nobody had documented
  • The format. The archive's two big files use a custom sorted-table format, similar to Google's LevelDB, with no library and no documentation. We wrote the parser from the raw bytes. Two details cost an afternoon each: the "raw size" field is actually the size on disk, and the index block is the only block that's never compressed.
  • Moving 1.1 TB through a disk that couldn't hold it. The machine had far less free disk than the archive, and downloading ran about 9× faster than uploading. So the uploader stored each 64 MiB piece as its own object, verified its size and checksum, and only then deleted the local copy. The download paused whenever free disk ran low. It took five days and many restarts, with no data lost. An earlier attempt using multipart uploads had lost data twice, because the storage service can silently clean up unfinished parts.
  • Extraction. The first version built 2.2 million nested dictionaries and ran out of memory. The shipped version keeps the tree as raw bytes. With 8 workers it took 5–8 hours instead of about 45. The output was 3,211 Parquet files, 89 GB, each checked byte for byte after upload.

2 · The table we threw away

The obvious design is one row per URL. We'd already built it once, for a few brands. It cost 632 bytes per row: 215 million URLs took 136 GB. Even with one row per document instead of per URL, that's about 1.3 TB of Postgres (for all 13.7 billion URLs, 8.7 TB), for a table the agent only ever reads one manual at a time.

That access pattern decided the design. Every question is about one vehicle, so one manual, and nothing ever needs two manuals at once. So the unit of storage became the manual:

manual_docs (
  manual_id   int PRIMARY KEY,
  arrow       bytea,  -- the manual, compressed
  fast_index  bytea   -- its ranking index
)

That's 70,749 rows, one per manual. One of the 70,750 manuals was lost to an export error. The documents themselves take under 8 bytes each, 16 GB in total. With the ranking index included, the whole table is 69 GB, about 19× smaller than one row per document. Three quarters of that is the ranking index (section 3): we spend disk to make every search fast.

Most of that saving came from deciding what not to store. We dropped a 74-character page hash, which was longer than the table-of-contents path it identified. And table-of-contents paths repeat their first levels thousands of times, so compressing them column by column shrank one manual's paths from 20.6 MB to 0.6 MB.

Log-scale bars of bytes per document: one row per document 632 bytes (~1.3 TB); one row per manual keeping the page hash 49.91 (94.5 GB); zstd-3 9.78 (19.9 GB); zstd-9 7.71 (15.7 GB, chosen); zstd-19 6.87 (13.9 GB, 71 hours to encode).
Fig. 02Choosing what one row holds mattered far more than choosing a compressor. Maximum compression (zstd-19) would have saved another 2 GB for 70× the encoding time.

Loading it hit the usual wall. Inserting one manual at a time through the cluster tunnel ran at 46 KB/s. Postgres's bulk COPY was 31× faster. Every manual arrived with none missing and none extra, and the share of manuals the assistant could actually use went from 0.4% (304 manuals loaded) to 100%.

3 · Search without a search engine

Search never runs over two billion documents. It runs over one manual at a time: find the vehicle, read its manual's single row, and rank in memory.

Six steps: the agent calls the tool with make, model and year; a local SQLite lookup finds the manual (~0.1 ms); one Postgres primary-key read (5–10 ms); ranking in memory (2–97 ms) plus a question embedding (220–420 ms); up to six pages back to the agent; page content and images read from our own copy of the archive.
Fig. 03One search, end to end. Two billion documents, but each search reads exactly one row. Most of the ~300 ms goes on one call that turns the question into an embedding.

Each document's score blends three signals: meaning (60%), keyword match (30%), and whether it's the right kind of operation, such as removal or inspection (10%). Penalties push down navigation pages and pages for a different car. The meaning signal doesn't embed two billion documents. It embeds the 170,000 distinct component names used across all the manuals, which cost about two cents.

Ranking inside a big manual was the last slow step, so each manual got a precomputed index. It's 16–17× faster on typical manuals and 237× faster on the largest, which went from 23 seconds to under 0.1. Before shipping, we checked that the fast ranker returned identical top-10 results to the slow one, across 25 manuals and 6 kinds of question. That check caught three bugs a spot check would have missed.

Log-scale bars of ranking time: a compact SUV manual 38.47 ms to 2.41 ms (16×), a heavy pickup manual 991 ms to 57 ms (17×), largest manual 23,009 ms to 96.9 ms (237×).
Fig. 04Ranking time inside one manual, before and after the precomputed index. Building it for all 70,749 manuals took about 11 hours on four workers.

4 · Design the tools around how the agent fails

The agent never writes SQL. It gets a small set of typed tools: find manual pages, find diagrams, find and open bulletins, and a lookup that first shows it the car's own table of contents, about 125 top-level sections. That way it sees how this manual names things before it searches.

Two choices did most of the work:

  • Suggest, don't filter. Early on, the agent picked a section and we filtered to it. One wrong guess cut 332 candidates to 68 and removed the right page. Now the agent's guess only reorders results. It never removes them.
  • Use the manual's words, not ours. "Water pump" found nothing in manuals that say "Coolant Pump". When results are weak, the tool now returns try_these: terms read off the matched manual's own table of contents. The agent searches again using them.

Pages and images come from our own copy of the archive, one direct read per page. That replaced a web scraper that took 4 seconds a page on a good day, 30 seconds on a bad one, and eventually stopped responding.

Results

measurebeforeafter
manuals the assistant can use0.4%100%
returned pages for another vehicle (225 searches: 15 cars × 15 question types)60%4.4%
searches the agent needs for a torque question7–122
full answer to a torque question, end to end147 s28 s
load the pages an answer cites (10-page test)3 of 10 load, 6.4 s10 of 10, 0.8 s
navigation pages ranked first17%0%

A search takes about 0.3 seconds. A full answer still takes about 28, because the agent searches, reads the pages, then writes. The drop from 147 seconds came mostly from the agent needing 2 searches instead of 7–12, and from pages loading in under a second instead of several.

  • On a 60-question benchmark, each question with a known right page, the agent's first search returned that page 59 times. All 60 were reachable. Half of the questions were held back until tuning was finished.
  • Over 14 days in production, no search failed. 11 questions were about cars that have no manual in the archive.

Fixing wrong-vehicle results mattered most to the agent. In one 2011 truck manual, 96% of the pages belonged to other vehicles that share it. The agent kept searching because the results looked wrong, and they were.

What's still broken

  • About 1 in 25 results is still for the wrong vehicle. That share was 60% before the fix.
  • The archive has gaps. In 14 days, 11 questions were about cars with no manual. No search improvement fixes that.
  • The query embedding call is now nearly all of the search time. Caching common questions is the obvious next step.
Under the hood: fitting it into a 5.5 GB server

The search server was killed for running out of memory at 5.5 GB, under nine questions at once. The caches were the obvious suspect, and they weren't the cause. The server could see 16 CPU cores, so the C memory allocator was allowed up to 128 separate memory pools. One environment variable, MALLOC_ARENA_MAX=2, was the actual fix. Alongside it, we memory-mapped the embedding matrix and moved the vehicle lookup into a SQLite file, which cut that part from 227 MB to 42 MB.

Three plausible optimisations were reverted after measuring them. Shrinking the caches turned 3-minute report flows into 15-minute timeouts. A small fast cache lost to constant reloading. And capping cache sizes in bytes added 189 MB.

Lessons

  • Let the questions pick the storage unit. One vehicle, one manual, one row turned 1.3 TB into 69 GB.
  • Check properties; don't assume them. The 300 MB deduplicator only works because "each manual sits in one shard" was verified first.
  • Prove a fast path matches before shipping it. The 237× ranker shipped because a test showed identical results.
  • Measure memory before cutting it. The fix for the out-of-memory crashes was one environment variable. The intuitive fixes made it worse.

Thirteen billion URLs sounds like a search-engine problem. It turned out to be a data-modelling problem. Once every question had exactly one manual, the search engine fit in a primary key. This archive is one of two sources behind the same assistant. The other is a knowledge graph of current factory documents.

Aryan Gurav — MumbaiMore writingTop