billflare.

A usage circuit breaker for Cloudflare Workers

Yingjie Zhao describes a self-facing circuit breaker that pauses cron jobs on his Workers-based news aggregator as monthly usage nears plan allowances.

Products
WorkersKVQueues
Source
Author experienceYingjie Zhao’s blog
Author
Yingjie Zhao

Key points

  • Every five minutes, the cron scheduler queries the GraphQL Analytics API and the Observability Telemetry API for month-to-date usage across eight resources and caches it in KV. Between checks, it reads the cached state from KV.
  • Thresholds differ by resource: every resource warns at 80%, but only resources with costly overages that pausing cron can reduce (KV operations, Queues, Observability) trip at 90% and recover below 85%. Workers requests and CPU only warn. The gap between trip and recover prevents oscillation.
  • If the usage API fails, the breaker keeps its last known state. Warnings are deduplicated per resource per month and trip alerts once per month, sent by email and Feishu. The author reports that it caught an 82% KV-read spike early in a month, before reaching the trip threshold.

Original sources

  1. Undated

D1

D1 status writes: an author reports a 150-dollar charge and refund.

@wofuhuola describes a generated tool writing Reddit post statuses globally every five minutes and deleting expired rows. The author says one month cost 150 dollars, went unnoticed for three months, and was later refunded after an appeal.

Author experienceWorkers +4

Cloudflare billing pitfalls thread

The author organizes Cloudflare billing risks by product and shares experience with budget alert emails.

Community resourceWorkers +4

cf-usage-guard

An open-source library that reads account usage from the Cloudflare GraphQL API and circuit-breaks individual Worker bindings before overages.