Originally published on michael-kaminski.io.
I added an API key to a tool that calls Semantic Scholar, expecting fewer throttled requests. I got more. Keyless, 8 of 18 calls were throttled. Keyed, 9 of 10 cold builds were.
The conclusion first: a rate limit is a number the upstream publishes, and you pace to it; you do not discover it one 429 at a time. The cache decides how often you pay that limit at all, and the one thing the cache must never hold is the failure.
The tool is lineage, public, 7 commits on 2026-11-28, live at lineage-graph.vercel.app. Paste an arXiv link and it draws the paper's references as a git log --graph: which earlier ideas merged into it and how much of the paper each branch owns. Next.js on Vercel's CDN, no database, no model on the request path. Every number below is from the repository as cloned on 2026-11-29 at 0788d3a, its decision log, or requests I made the same day.
Two upstream calls per paper, and both of them can be refused
A cold build makes exactly two calls to Semantic Scholar. The first fetches the paper's references with their citing sentences, citation intent and influential flag, up to 1,000 per page. The second posts the paper and every reference it found to the batch endpoint, 500 ids at a time, and gets back which references cite each other.
The parent of each reference is the most recent earlier reference it cites. Branch ownership is one point per paper, plus two for an influential citation and one for a methodology citation. All of that is arithmetic that runs in under 21 milliseconds for five graphs, including schema validation. The two calls are the entire cost of a paper.
Semantic Scholar's published terms, as read on 2026-11-29: unauthenticated requests share a pool limited to 1,000 requests per second across every unauthenticated user in the world, and an API key gives you 1 request per second of your own. The repository's first build decision, D10, said "no sleeps between calls." That decision lasted one day.
Keyless: 44% of calls throttled and a p95 of 11.4 seconds
The shared pool has no per-client rate, so it is as fast as the quietest second and as slow as the busiest one. Building the five seed graphs live on 2026-11-28, 8 of 18 calls came back 429 and were retried. A single probe of the Mistral 7B paper went through clean: 2 calls, 0 retries, 1,929 ms end to end.
Ten random papers through the live deployment the same day told the fuller story. Cold builds that succeeded took 4,634 ms at p50 and 11,384 ms at p95, against a 3,500 ms budget. Three of the ten returned a 503, and all three succeeded on the next request.
The two upstream calls alone took between 1.1 and 5.3 seconds when they were not retried at all.
The function's own overhead, end to end minus time inside Semantic Scholar, was 159 to 339 ms across graphs of 29 to 146 nodes. The code is not the latency. The pool is.
[Figure: Horizontal bar chart on a log scale. Cold keyless requests take 4,634 ms at p50 and 11,384 ms at p95, both past the dashed 3,500 ms budget line. A single probe with no retries took 1,929 ms. Function overhead is at most 339 ms. Warm requests served from the CDN take 57 ms at p50 and 74 ms at p95.]
Cold and warm are two orders of magnitude apart on the same route. The code contributes at most 339 ms of the cold number; the rest is waiting on a pool shared with everyone.
The key made it worse: 9 of 10 builds throttled
The key arrived on 2026-11-28 and the next ten cold builds throttled nine times. Every one of the nine was the second call. The batch request fired the instant the references request returned, which is well under one second after the previous call started, and the key's limit is a strict one request per second per client.
Five of those nine builds fell back to the degraded mode, where the paper's metadata comes from a single GET and the graph is drawn in lanes by citation type with no branches. One returned a 503 to the reader.
The shared pool was never counting my requests. The key is.
The fix is decision D10b, which reverses "no sleeps": when S2_API_KEY is set, successive calls within a build start at least 1,050 ms apart. Keyless stays unpaced, because pacing a pool you do not control buys nothing. The extra 50 ms is slack.
[Figure: Column chart. Keyless shared pool: 8 of 18 calls retried, 44 percent. With an API key and no pacing: 9 of 10 cold builds throttled, 90 percent. With the key and calls paced 1,050 milliseconds apart: a dashed empty column labelled TBD, not measured yet.]
The key did not lower the throttle rate; the pacing will. The third column is empty on purpose, because the keyed, paced run has not been measured.
Here is the cost of that fix, stated plainly. A keyed cold build now has a floor of 1,050 ms before the second call can even start, so the fastest keyed build is slower than the 1.1 seconds the shared pool managed on a quiet second. The key trades a fast, unpredictable path for a bounded, slower one. For a page a reader is staring at, bounded wins.
Retry twice for a reader, six times for a robot
On the request path the client retries a 429 or a 5xx twice, waiting 1 second then 2, honouring the upstream's Retry-After up to 5 seconds, with an 8 second timeout per call and a 25 second cap on the whole function. After that it throws busy and the reader gets a 503 with a Retry-After of 10 and a "retrying in 10 s" message with links to the seed papers.
The seed builder, which runs on my machine with nobody waiting, retries six times at 3 seconds times the attempt number, honouring Retry-After up to 30 seconds. Same client, same upstream, different policy, because the question a retry policy answers is "who is waiting," not "how flaky is the API."
The cache is the rate limiter
A successful graph is returned with s-maxage=2592000, stale-while-revalidate=604800: 30 days fresh on the CDN, then 7 more days during which a stale copy is served while one request rebuilds it. A paper costs Semantic Scholar two calls on its first view and zero on every view after, for a month. Warm requests measured 57 ms at p50 and 74 ms at p95 on 2026-11-28, with 7 of 7 repeats served from cache.
The share card for a paper reads the graph back through the same CDN route and never rebuilds it, so a crawler fetching the card does not double the upstream load. A paper Semantic Scholar has not indexed is cached as a 404 for an hour. A degraded lanes-mode graph is cached for 300 seconds, so the next viewer after that gets a chance at the full build.
A 503 is cached for zero seconds. no-store, every time. Decision D11 gives the reason in five words: errors must not pin in the CDN. A throttled minute served to every reader of that paper for the next 30 days would be the worst outcome in this whole design, and it is a one-line mistake away.
The capacity arithmetic follows from the key. Two calls at 1 request per second is 0.5 cold builds per second, 1,800 an hour. A Show HN hour at 500 new papers is 28% of that, 56% if traffic arrives in 2x bursts, under the 70% flag in the envelope.
By Little's law, 0.14 builds per second times 2.1 seconds each is 0.3 functions in flight. One free tier holds that, and a popular paper is computed once.
What I measured on 2026-11-29
From my own machine I requested three papers that were not in the cache, each twice. Four cold attempts produced one 503, with retry-after: 10 and cache-control: no-store, which succeeded on the immediate retry. One cold build that succeeded took 5,822 ms. Every warm repeat was x-vercel-cache: HIT at 132 to 149 ms, including the paper that had just failed.
That is the design doing what it says: the failure cost the reader one retry and cost the cache nothing, and the success is now free for a month.
The unit suite ran from a fresh clone in 1.39 seconds: 4 files, 84 tests, 84 passed, on Vitest 5.1.2 and Node 22.23.5. The tests that matter here are named for the contract: "429 → retry → success"; "429 × 3 → throws busy with Retry-After"; "throttled → 503 + Retry-After, never cached"; "keyed: successive calls start ≥ min interval apart; keyless: no pacing"; "batch throttled → HEAD via single GET, lanes mode."
What is still wrong
The keyless p95 is 11,384 ms against a 3,500 ms budget, a miss of 7,884 ms. Three in ten first viewers of a new paper saw a retry screen. The envelope marks the budget as gated on the key, which is honest and also means the production number a reader experiences today is the one that fails.
Every keyed row in the envelope is TBD. The pacing fix was committed on 2026-11-28 and pnpm measure has not been rerun with the key set. The second figure above has an empty third column for that reason. I would rather publish the empty column than a number I made up.
The 30-day cache means a graph can be a month stale. References do not change, but Semantic Scholar's influential flags and citation counts do, and a reader who notices will be looking at numbers up to 37 days old. The 300 second cache on a lanes-mode graph means up to five minutes of readers see a branchless graph after one throttled batch call.
Headroom against the 1 request per second limit and the 5xx error rate are both TBD until the per-call trace that commit 0788d3a added, one line per miss with endpoint, status, milliseconds and Retry-After, has been read back across a real day of traffic. A metric nobody has looked at is not a metric yet.
The rule I would carry to the next one
Read the upstream's published limit before writing the client, and pace to it. A retry handles the second you were unlucky; pacing handles the rate you were always going to hit. Then make the cache lifetime match how long the answer stays true, which for a citation graph is weeks, and make the failure lifetime zero.
Two calls per paper is the same discipline as zero model calls per request: find the step that costs money or time, count it, and build everything else so that count is the whole bill. Then measure the row you changed. Mine is the keyed column, and it is still empty.
If you have paced a client against a strict per-second key and have the throttle rate after pacing, I would trade notes.