Repository navigation
fix(web): cache api answers at the edge to stop billed worker hops - #125
Merged
Merged
Conversation
Every fetch from the site's Pages Functions to the API's public URL is a billed Worker request on Workers Free, even when the API answers from its own edge cache. On 2026-11-17 that made f1-api 41k of the account's 100k daily requests. Answers are held no longer than a page is, so backfills and SNAPSHOT_VERSION bumps show up as fast as before.
Deploying f1-prediction-platform-web with
|
| Latest commit: |
7b401a7
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b389972e.f1-prediction-platform-web.pages.dev |
| Branch Preview URL: | https://fix-api-request-budget.f1-prediction-platform-web.pages.dev |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
f1-prediction-platform-api | 7b401a7 | Nov 17 2026, 09:39 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On 2026-11-17 the account used 84.5k of Workers Free's 100k daily requests by 19:41 UTC.
f1-apialone took 41k, and most of those were this site's own server fetches to the API's public URL, about 2.7 per page render. Each one is a billed Worker request, even when the API answers from its edge cache.An answer is never held longer than a page is, so a backfill or a
SNAPSHOT_VERSIONbump shows up as fast as before. Errors, 404s,no-storeand answers without a max-age are never stored. The cache is off inastro devand in the browser (search and compare). A Service Binding would remove the hop entirely, but Cloudflare's docs don't say whether binding calls count toward the Free daily limit, or whether the API's Cache API still works when it's reached through one.docs/deployment.mdalso gains the dashboard WAF rule that blocks crawlers onf1-api: Meta'smeta-webindexerignores the API'srobots.txtand calls API URLs directly.Evidence
f1-apihandled 41,183 requests on 11-17, against 14,420 Pages Functions runs. From 11:00 UTC the two moved together at about 2.7 API calls per render.tests/unit/lib/apiCache.test.ts, 10 tests:max-age=86400is capped to 3600 on a Tuesday and 300 on a Saturday; a shorter API max-age is keptno-storeand answers without a max-age are never storedastro checkreports 0 errors; ESLint andbun run buildpass.Merge Danger
Door: two-way
Reverting the commit puts back the direct fetch. Entries already stored expire within an hour.
Blast Radius: site-wide
Every server-rendered page reads the API through this cache. A misbehaving cache would show data up to 1 h old (5 min on race weekends), the same staleness the page cache already allows.