frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

SHOW HN: A usage circuit breaker for Cloudflare Workers

14•ethan_zhao•1h ago
I run 3mins.news (https://3mins.news), an AI news aggregator built entirely on Cloudflare Workers. The backend has 10+ cron triggers running every few minutes: RSS fetching, article clustering, LLM calls, email delivery.

The problem: Workers Paid Plan has hard monthly limits (10M requests, 1M KV writes, 1M queue ops, etc.). There's no built-in "pause when you hit the limit", CF just starts billing overages. KV writes cost $5/M over the cap, so a retry loop bug can get expensive fast.

AWS has Budget Alerts, but those are passive notifications, by the time you read the email, the damage is done. I wanted active, application-level self-protection.

So I built a circuit breaker that faces inward, instead of protecting against downstream failures (the Hystrix pattern), it monitors my own resource consumption and gracefully degrades before hitting the ceiling.

Key design decisions:

- Per-resource thresholds: Workers Requests ($0.30/M overage) only warns at 80%. KV Writes ($5/M overage) can trip the breaker at 90%. Not all resources are equally dangerous, so some are configured as warn-only (trip=null).

- Hysteresis: Trips at 90%, recovers at 85%. The 5% gap prevents oscillation, without it the system flaps between tripped and recovered every check cycle.

- Fail-safe on monitoring failure: If the CF usage API is down, maintain last known state rather than assuming "everything is fine." A monitoring outage shouldn't mask a usage spike.

- Alert dedup: Per-resource, per-month. Without it you'd get ~8,600 identical emails for the rest of the month once a resource hits 80%.

Implementation: every 5 minutes, queries CF's GraphQL API (requests, CPU, KV, queues) + Observability Telemetry API (logs/traces) in parallel, evaluates 8 resource dimensions, caches state to KV. Between checks it's a single KV read — essentially free.

When tripped, all scheduled tasks are skipped. The cron trigger still fires (you can't stop that), but the first thing it does is check the breaker and bail out if tripped.

It's been running in production for two weeks. Caught a KV reads spike at 82% early in the month, got one warning email, investigated, fixed the root cause, never hit the trip threshold.

The pattern should apply to any metered serverless platform (Lambda, Vercel, Supabase) or any API with budget ceilings (OpenAI, Twilio). The core idea: treat your own resource budget as a health signal, just like you'd treat a downstream service's error rate.

Happy to share code details if there's interest.

Full writeup with implementation code and tests: https://yingjiezhao.com/en/articles/Usage-Circuit-Breaker-for-Cloudflare-Workers

Comments

kopollo•1h ago
When collecting RSS feeds, I recommend setting a limit so that each RSS source is pulled every 10 minutes.
ethan_zhao•1h ago
That's a solid default. I actually set my RSS polling interval to 1 hour, most sources I follow don't update frequently enough to justify anything shorter. Every 10 minutes works too, but you might end up burning cycles on unchanged feeds.
photobombastic•1h ago
This is a real problem. I've heard similar stories from people running CI pipelines — a retry loop bug burns through your entire monthly Actions minutes budget in hours, and there's no built-in circuit breaker there either.

The approach of tracking usage locally and cutting off before you hit billing overages makes a lot more sense than trying to parse the billing API after the fact. Prevention over detection.

Could be cool to set per-worker limits in addition to the global ones.

ethan_zhao•1h ago
Totally. When I first launched my project, I literally couldn't sleep at night, kept worrying that some bug in my code would spiral into a self-inflicted Denial of Wallet attack by morning. That fear is what pushed me to build the circuit breaker early on. Prevention over detection is spot on.
westurner•23m ago
> The core idea: treat your own resource budget as a health signal, just like you'd treat a downstream service's error rate.

This is more state. The deployed app is then more stateful and thus more complex. If there is more complexity, there are probably more failure cases.

But resource budget quota signals are a good feature, I think.

Apps should throttle down when approaching their resource quotas.

What is the service hosting provider running to scale the service up and down?

Autoscaling: https://en.wikipedia.org/wiki/Autoscaling

k8s ResourceQuotas: https://kubernetes.io/docs/concepts/policy/resource-quotas/

willswire/union is a Kubernetes Helm chart for self-hosting cloudflare/workerd: https://github.com/willswire/union

Helm docs > intro > Using Helm: https://helm.sh/docs/intro/using_helm/ :

> Helm installs resources in the following order:

> [..., ResourceQuota, ..., HorizontalPodAutoscaler, ...]

How could this signal and the messaging about the event be standardized in the Containerfile spec, k8s, Helm?

Containerfile already supports HEALTHCHECK. Should there be a QUOTACMD Dockerfile instruction to specify a command to run when passed a message with the quota status?

iam_circuit•17m ago
This pattern should be default for any metered service. Budget exhaustion is a security failure mode — accidental (retry loops) and adversarial (amplification attacks) look identical to billing.

The gap: most platforms treat billing as purely financial. But spend limits are actually a form of resource isolation. When your Workers hit quota, you don't just lose money, you lose availability. Treating budget as a circuit breaker turns it into active defense.

Show HN: Svglib a SVG parser and renderer for Windows

https://github.com/bibhas2/svglib
1•leopoldj•2m ago•0 comments

The ugly history of regime change

https://www.profgmedia.com/p/this-time-is-different
2•shimm723•3m ago•0 comments

What software knowledge will stay relevant?

https://www.natemeyvis.com/what-software-knowledge-will-stay-relevant/
1•speckx•4m ago•0 comments

Show HN: Base Layer – Open-source behavioral compression from any text

https://www.base-layer.ai/
1•agulaya24•4m ago•0 comments

Para-biathlete wins silver using ChatGPT as his coach

https://www.theguardian.com/sport/2026/mar/09/ukraine-winter-paralympics-chat-gpt-artificial-inte...
1•defly•5m ago•0 comments

Amazon is holding a mandatory meeting about AI breaking its systems

https://twitter.com/lukolejnik/status/2031257644724342957
2•lwhsiao•5m ago•0 comments

Show HN: Claude Tuner – Monitor your Claude usage and find the right plan

https://claudetuner.com
1•xlos21•6m ago•1 comments

CragCLI – a new calculator for the command line

https://cragcli.info
3•librasteve•7m ago•1 comments

Show HN: Jottit – Reviving the Original from 2007

https://jottit.org
1•simonbc•7m ago•0 comments

Stripe: Billing for LLM Tokens

https://docs.stripe.com/billing/token-billing
1•tosh•7m ago•0 comments

Unlocked SaaS, file source as truth?

1•abmmgb•8m ago•1 comments

Understanding OBD2 codes (past, present, future)

https://crewchief.cc/blog/understanding-obd2-codes
1•meandave•8m ago•0 comments

Ask HN: What Happened to Llama Models?

1•elpakal•8m ago•0 comments

Meta to Acquire Moltbook

https://www.bloomberg.com/news/articles/2026-03-10/meta-to-acquire-moltbook-viral-social-network-...
2•marc__1•9m ago•0 comments

Disorder Drives One of Nature's Most Complex Machines

https://www.quantamagazine.org/disorder-drives-one-of-natures-most-complex-machines-20260309/
2•Brajeshwar•12m ago•0 comments

Spacecraft's impact changed asteroid's orbit in a save-the-Earth test

https://apnews.com/article/asteroid-nasa-draft-dimorphos-9abccd32d4cb532a66249dd6145685cb
2•Brajeshwar•12m ago•0 comments

Volkswagen to cut 50k jobs as profits drop

https://www.bbc.com/news/articles/c4gqyyly9v8o
1•gehwartzen•13m ago•0 comments

Microsoft 365 confirms new premium tier, stuffed with AI and few discounts

https://www.theregister.com/2026/03/09/microsoft_adds_a_premium_tier/
1•Brajeshwar•13m ago•0 comments

Smol AI WorldCup: What Small LLMs Can Do

https://huggingface.co/blog/FINAL-Bench/smol-worldcup
3•seawolf2357•13m ago•0 comments

Debian decides not to decide on AI-generated contributions

https://lwn.net/SubscriberLink/1061544/125f911834966dd0/
11•jwilk•13m ago•1 comments

License Laundering and the Death of Clean Room (The Chardet Saga)

https://shiftmag.dev/license-laundering-and-the-death-of-clean-room-8528/
1•allixsenos•13m ago•0 comments

We are building data breach machines and nobody cares

https://idealloc.me/posts/we-are-building-data-breach-machines-and-nobody-cares/
2•idealloc_haris•16m ago•0 comments

Turing Award winner and former Oxford professor Tony Hoare passed away

https://blog.computationalcomplexity.org/2026/03/tony-hoare-1934-2026.html
30•speckx•16m ago•2 comments

Non-blocking SQLite for Node.js. Ported 100% of better-sqlite3 tests

https://www.npmjs.com/package/better-sqlite3-pool
1•dilipvamsi•17m ago•1 comments

AI Agent hacked McKinsey's chatbot and gained full read-write access in 2 hours

https://www.theregister.com/2026/03/09/mckinsey_ai_chatbot_hacked/
1•smurda•17m ago•0 comments

Forward to Hell?

https://labs.ripe.net/author/mkoch/forward-to-hell-on-misusing-transparent-dns-forwarders-for-amp...
2•jruohonen•17m ago•0 comments

Elements of AI Agents

https://academy.dair.ai/courses/elements-of-ai-agents
1•omarsar•18m ago•0 comments

Portable Secret is now open source

https://blog.alcazarsec.com/tech/posts/portable-secret-is-now-opensource
1•alcazar•19m ago•0 comments

Why $100 Oil Isn't Going to Spark a New Shale Boom – Oilprice.com

https://oilprice.com/Energy/Crude-Oil/Why-100-Oil-Isnt-Going-to-Spark-a-New-Shale-Boom.html
1•bilsbie•20m ago•0 comments

JSON Documents Performance, Storage and Search: MongoDB vs. PostgreSQL

https://binaryigor.com/json-documents-mongodb-vs-postgresql.html
1•PaulHoule•21m ago•0 comments