The problem
The brief was one sentence: send the same promotional email to 1,000,000 recipients, each with their own name, as fast as reasonably possible. It also asked for every prompt used to build it, so the repository keeps the Claude Code transcripts next to the code.
Speed is the easy half. Putting a million names into a template takes milliseconds. The work is a million deliveries through a provider that limits the request rate, fails now and then, and rejects some addresses. The hard half is the failure case. If the process dies at email 600,000, running it again sends 600,000 people a second copy. Every customer who gets a duplicate promotion sees it, and spam reports cost the sending domain its reputation. A slow campaign can recover; a duplicated one cannot.
What it does
- Streams the list.
recipients.csvis read line by line and cut into batches of 1,000. The file is never loaded whole. When 20 batches are in flight, the reader waits, so memory depends on the batch size and the concurrency, not on whether the list has 1 million rows or 100 million. - One request per batch. A batch goes to the provider as one bulk request: a shared template and 1,000 sets of per-recipient values, in the shape of SendGrid's v3 personalizations. The provider fills in each name, so a million emails are 1,000 requests, and no finished message is built on the client.
- Records every batch it finishes. After the provider accepts a batch, its number is written to
campaign.checkpointand flushed to disk. Running the same command again skips every recorded batch. - Gives every failure one path. Rate limits wait, server errors retry, a bad address goes to
rejected.logand is never retried, and any other error stops the campaign with its progress saved. - Shows progress live. A status page at
localhost:3210gets the counters over Server-Sent Events, about ten times a second. It listens on the loopback address only. - Runs dry by default. A simulated provider adds 80 ms of latency with ±30% jitter, fails 1% of batches and rejects 0.1% of recipients. Flags add a request quota (
--sim-quota) or a hard crash (--crash-after). The real provider path needs--transport esp, an API key and--rate.
Decisions
One process, no queue
The work waits on the network; the processor is idle. One Node event loop can keep thousands of requests waiting at once, so worker threads would add complexity and no throughput. A 20-line semaphore is all the concurrency machinery. There is no Redis or job queue either: the checkpoint file gives the durability a queue would, and nothing has to run next to the sender. package.json has no runtime dependencies; TypeScript, tsx and the Node types are dev dependencies only.
The batch number is the unit of record
For a given input file and batch size, batch 412 always holds the same 1,000 recipients. The checkpoint is a header line and one integer per finished batch, so 1,000 small numbers describe a million sends, and no email address is written to it. The header records the input file and the batch size, and the sender refuses to resume when either has changed, because every batch number would then point at the wrong people. A test covers both refusals. Sending, retrying and resuming all work on the same unit: the batch.
Record after the provider accepts, never before
The order is fixed in the pipeline: send the batch, write its number and fsync the file, then update the counters. A crash between the first two steps means the batch is sent again on resume. Writing the number first would turn the same crash into recipients who are marked done but never got the email, and nothing could detect them afterwards. Between a bounded duplicate and a silent gap, the duplicate is the side to choose. One fsync per batch is 1,000 a campaign. A full million-recipient dry run took 8.0 seconds on my laptop with all of them on.
The tests found a bug here. If a crash cut off the last line half-written, the next number was appended onto the broken bytes, and that batch's record was lost on the next load. The checkpoint now ends a torn tail with a newline when it opens, and a test writes garbage to the end of the file to prove it.
Two budgets for two kinds of failure
A 5xx response or a dropped connection is a fault. It gets 5 attempts, with a backoff of 250 ms, 500 ms, 1 s and so on up to 30 s, each multiplied by a random factor between 0.5 and 1.5, so twenty workers that failed together do not retry together. A Retry-After header replaces the guess when the provider sends one.
A 429 is congestion, not a fault, so it does not use up attempts. The batch waits the provider's Retry-After plus up to 100 ms of jitter, until it has waited 60 seconds in total. After that, the campaign stops with a message that names the fix: set --rate at or below the quota. The comment in pipeline.ts records why the budgets were split: an earlier version counted 429s as attempts, and a full run without --rate stopped at 18% when one batch lost five races for the quota window in a row.
Concurrency and rate are separate limits
The semaphore limits how many batches are in flight, which protects this process's memory and sockets. A token bucket limits how many requests start each second, which is what the provider's quota counts. It starts empty, so a run does not burst past the quota in its first second, and a retry takes a token like any other request. With only the semaphore, the request rate is concurrency divided by the provider's latency, and 429s become the flow control. For that reason, the real provider path refuses to start without --rate.
The first two screenshots show the difference. Against a simulated quota of 50 requests a second, my runs without --rate got between 900 and 1,500 429 responses. With --rate 50 they got between 20 and 40, in about the same 20 to 22 seconds.
Test the promise, not only the parts
There are 15 tests, run with Node's built-in test runner. The two end-to-end tests send 5,000 recipients through the real pipeline with a fake provider. The first adds transient failures and permanent rejects and checks that every recipient was accepted or rejected, never both, and never twice. The second stops the campaign with a fatal error after 20 batches, resumes with a healthy provider, and checks that the two runs sent to separate recipients and together reached all 5,000. The other tests cover the checkpoint, the retry rules, Retry-After, the 429 time limit and the semaphore. Besides the torn checkpoint line, they found a second bug: the pipeline reported completion before rejected.log had finished writing.
Limits
- It is not exactly-once. The guarantee is at-least-once, with the duplicates limited to the batches in flight at the crash: with the default settings, at most 20 batches of 1,000. The built-in crash demo shows it. The simulated provider had accepted about 400,600 emails when it crashed, but only 400 batches were recorded, so the batch it was sending goes out again on the rerun. True exactly-once needs a per-batch idempotency key that the provider removes duplicates by. The transport has a place for it, but it is not built.
- It has never sent a real email. The provider transport is shaped like SendGrid's and points at a placeholder address. Outside the dry runs, it has only been run against a local HTTPS server in a benchmark script.
- Compliance is out of scope. The email carries an unsubscribe link and a postal address, but the sender does not check a suppression list, and there are no consent records.
rejected.logand the input CSV hold names and addresses in plain text with no retention rule. - One process per checkpoint, and nothing enforces it. The checkpoint file has no lock, so two copies started on the same file would both send.
- The CSV reader is minimal. It splits each line at the first comma. A line it cannot read is skipped, and it is neither sent nor logged.
- The live site is the submission's guide. surat.spindyzel.com is the start page and diagrams made for the brief, laid out for a laptop. The screenshots come from the status page during dry runs on my laptop.


