# How to build a per-Worker spending limit on Cloudflare · workerfuse

If you want to roll your own spending limit, here's roughly how I'd do it (because it's how I did it).

1.  Run a Worker on a cron, every 5 minutes.
2.  Query the GraphQL analytics API for usage since the start of the UTC day, or the last hour if that's earlier (otherwise your hourly window breaks right after midnight). Use 5-minute buckets. One query can cover Workers, Durable Objects, D1, KV, R2, Queues and more.
3.  Price it. I use list prices and ignore the included allowances on purpose, so the estimate runs high and a runaway trips early.
4.  Map each resource to the scripts that use it. This is the annoying part. A Durable Object namespace belongs to the script that defines the class. A D1 database or KV namespace gets charged to every script with a binding to it.
5.  If a script is over the hourly or daily limit, upload a stub version of it and deploy that. HTTP handlers return 503, cron and alarm handlers do nothing, and queue handlers call `retryAll()`. An empty queue handler acks the batch and you lose the messages.
6.  If the script has Workflows, terminate its queued, running and waiting instances too. A deploy doesn't stop them. workerfuse does up to 100 per status per run, and later runs pick up the rest while the script stays over its limit.
7.  Email yourself the rollback command.

## Things that bit me

*   New scripts and namespaces show up as unknown in analytics for about 20 to 25 minutes. During that window you can alert, but you can't tell who to pause.
*   The stub has to export the same Durable Object classes, or the deploy fails. Exporting them keeps the stored data too.
*   Only count usage after the script's latest deploy. Otherwise you fix the bug, roll back, and the guard pauses you again for the old usage. Ask me how I know.
*   The guard runs on Cloudflare. If Cloudflare is down, so is the guard. Not much to do about that one.

Most of the guard logic is one TypeScript file. If you'd rather not maintain it, [workerfuse](/signup) is this design, and you can self-host it or let us run it.

## Pause the runaway Worker. Keep the rest running.

workerfuse checks your Cloudflare spend every five minutes and pauses any Worker over its limit.

[Start free trial](/signup)

## Keep reading

[

Spend limitsNovember 13, 2026

### Cloudflare spending limits vs pausing one Worker

Cloudflare now has spending limits for Workers and Durable Objects. They're account-wide and block the whole product. Here's how that compares to pausing only the runaway Worker.

](/blog/cloudflare-spending-limit)[

Case studiesNovember 13, 2026

### Cloudflare billing horror stories: four runaway bills from 2026

A $34,895 alarm loop, a $10,811 bill from an abandoned side project, a ~$36,000 queue loop, and $4,586 of D1 writes. What broke, how long it ran, and what Cloudflare did about it.

](/blog/cloudflare-billing-horror-stories)[

Durable ObjectsNovember 13, 2026

### How a Durable Objects alarm loop runs up your Cloudflare bill

A Durable Object alarm that keeps rescheduling itself racks up requests, storage writes and duration. What that costs at list price, and how to stop it.

](/blog/durable-objects-alarm-loop)
