← Binderdex dev log

I let the catalog pipeline use all the cores

#automation#infra#product

Eight parallel lines run wide across the canvas, squeeze through one amber gate with four slots, and leave as a single file of small squares

Generating the full idea catalog took my whole evening, and for most of it the CPUs sat idle waiting on the network. The pipeline ran one subject at a time, with one render limiter per subject.

It now finishes in minutes. The work was deciding where concurrency is allowed, more than adding it.

The idea catalog is the set of binder idea pages on Binderdex, a Pokémon card collection and price app. Each page is a themed 3x3 binder page for collectors to browse, with a "Make it my binder" button. A subject is the theme behind one page, and the pipeline builds one page per subject.

Measure the stages, then sort them

The idea-catalog pipeline for Binderdex has five stages. It fetches concepts from the LLM, meaning theme ideas. It builds a candidate pool, the cards that could fill a theme's page. It assembles pages from those cards, renders each page as an image, then embeds and scores it. An embedding is a vector for comparing pages. I measured p50 and p95, the median and 95th-percentile times, for each stage first.

Network-bound stages (concepts and the pool) run wide through a bounded map. It returns results in input order and isolates failures.

export async function mapBounded<T, R>(
  items: readonly T[],
  limit: number,
  worker: (item: T, index: number) => Promise<R>,
): Promise<PromiseSettledResult<R>[]> {
  const gate = pLimit(limit);
  return Promise.allSettled(
    items.map((item, index) => gate(() => worker(item, index))),
  );
}

CPU-bound stages (assembly and rendering) share one limiter sized to the performance cores, the fast cores on the machine, so a batch of 8 subjects can't fight over them.

NETWORK-BOUND run wide through a bounded map Fetch concepts Build candidate pool Assemble pages Render Embed and score Append one JSONL receipt results keep input order, failures stay isolated CPU-BOUND one shared limiter sized to performance cores, so a batch of 8 can't fight RECEIPTS one serialized queue, one line per subject a rerun skips finished subjects
Wide where the wait is network, one shared gate where the work is CPU, and single file for the receipts.

Receipts make a rerun cheap

Earlier runs crashed at hour two and left me no idea which subjects had finished. Now each subject appends one JSONL line, a single JSON record on its own line of a log file, with its stage, timings and warnings, and a rerun skips finished work. Those appends go through one serialized queue, because concurrent appends to the same file would interleave. A failed write rejects its caller and never stalls the queue.

The test I lean on is named determinism at 1 vs 8. Concurrency is allowed to change wall time. It is never allowed to change the output.

This is the build log for Binderdex (www.binderdex.com) · All entries · Weekly essays