What this thread does
The problem
Serverless billing has no natural ceiling: a loop or a bot can multiply a small app's cost by thousands. An agent can write working Workers code that is expensive in a way no test shows.
What the source says
An r/CloudFlare post by u/alameenswe (2 May 2026; checked 2026-11-15) describes a bill of about $35,000 in one month for a side project with 81 users (author's numbers: about 3.1B KV writes, 16.6B KV reads, 4B Durable Object rows written, 574M KV list operations). The author's post found three causes:
1. Queue loop (about $15k). A queue-ingest worker forwarded the original write_mode (default async) to the internal API call, the API re-queued it, and the cycle repeated until an idempotency key stopped it. The fix was one line: force sync on internal calls. 2. Unbatched Durable Object writes (about $4k). 12 storage.put() calls per memory write; removing redundant writes cut it to 2. 3. kv.list() fallback on 95% of requests (about $2.8k) in API-key auth.
In later comments the author says most requests turned out to be bots, that a rate limiter existed but was never wired in (an empty map function) during a rushed migration from AWS, that he had used Claude Code in the work (he first said he had not), and that after adding Cloudflare's rate limiter requests fell to 163 per day. Treat the attribution of cost between loop and bots as the author's changing account.
What commenters pointed out
- The top reply blames unreviewed AI-written code; others note mistakes happen with or without AI.
- You cannot set a hard spend limit or prepay credits; several say a bill like this is unlikely to be forgiven, and that detection was missing.
- A commenter recommends a custom usage dashboard fed by your own Worker metrics, such as number of items put on a queue.
What to put in place
- Alert on usage. Cloudflare's notifications list includes a Usage Based Billing alert that fires when a product's usage passes a threshold you set; per the page it is available to pay-as-you-go accounts only (the page also lists Professional plans or higher), and its examples are Argo Smart Routing and Load Balancing. I could not confirm from that page whether Workers products appear as an option, so check the dashboard when creating it.
- Rate-limit before work. Related thread: per-user rate limiting for serverless APIs with Cloudflare's rate limit binding.
- Review cost paths in agent-written code: queue consumers that call your own API, writes per request, list scans, retries without idempotency.
How to describe it to your agent
Review this Worker for cost risks: any queue consumer that calls our own API (can it re-enqueue?), number of KV and Durable Object operations per request, any kv.list in a hot path, writes that can be batched, and missing rate limits or auth on public routes. For each, estimate operations per request and propose the smallest fix. Do not deploy.
Mistakes to check
- Internal calls that reuse the public path and its async or queueing behavior.
- A rate limiter that is defined but never applied to the route.
- Fallback lookups that scan instead of failing.
- No alert until the invoice arrives.
Limits
I did not reproduce any of this. The post's numbers and causes are the author's, partly revised in comments, and the post is also viewed by some as AI-written. Cloudflare may treat billing disputes case by case.
Sources
- Cloudflare notifications list was read. Checked: the Usage Based Billing notification fires when a product's usage passes a level you set; available to pay-as-you-go accounts only, with Professional plans or higher listed; the page gives Argo Smart Routing and Load Balancing as examples and does not say whether Workers is covered.
- Workers pricing was read. Checked: the page mentions no account spending cap or budget alert (its custom CPU limits are per invocation); KV writes and list requests at 5 dollars per million, KV reads 0.50 dollars per million, Durable Object SQLite rows written 1 dollar per million. Applying those prices to the author's counts (3.1B KV writes, 574M list operations, 4B rows written) gives roughly 15.5k, 2.9k and 4k dollars, consistent with the three causes quoted in the post.
- Workers rate limiting binding was read. Checked: it is configured in the Wrangler config and called with a key; limits are per Cloudflare location and eventually consistent, so it is not exact accounting.
Checked 2026-11-15: the Reddit post and comments were opened; the author's counts, the 35k total, the claims about Claude Code use, the AWS migration and the 163 requests per day remain self-reported. Nothing was reproduced.
Started from a post by @alameenswe, packaged by the editor. Original post