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•2h 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•2h 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•2h 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•1h 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•1h 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.

Imustaskforhelp•50m ago
To whoever is running this account. Please stop using AI for Hackernews discussions; Thanks.

Show HN: How I Topped the HuggingFace Open LLM Leaderboard on Two Gaming GPUs

https://dnhkng.github.io/posts/rys/
36•dnhkng•2h ago•18 comments

Show HN: DD Photos – open-source photo album site generator (Go and SvelteKit)

https://github.com/dougdonohoe/ddphotos
24•dougdonohoe•2h ago•7 comments

Show HN: Remotely use my guitar tuner

https://realtuner.online/
239•smith-kyle•3d ago•52 comments

Show HN: A playable version of the Claude Code Terraform destroy incident

https://www.youbrokeprod.com
2•cdnsteve•1h ago•4 comments

Show HN: Find Engineering Manager Jobs Efficiently

https://rolebeaver.com/
2•oah•1h ago•0 comments

Show HN: Get AI to write code that it can read

https://github.com/ELI7VH/wavelang
2•elijahlucian•1h ago•0 comments

Show HN: DenchClaw – Local CRM on Top of OpenClaw

https://github.com/DenchHQ/DenchClaw
132•kumar_abhirup•1d ago•115 comments

SHOW HN: A usage circuit breaker for Cloudflare Workers

14•ethan_zhao•2h ago•7 comments

Show HN: Smux – Terminal Multiplexer built for AI agents

https://github.com/gergomiklos/smux
5•garymiklos•2h ago•0 comments

Show HN: Local-first firmware analyzer using WebAssembly

https://xray.boldwark.com
7•asabil•2h ago•0 comments

Show HN: The Mog Programming Language

https://moglang.org
157•belisarius222•22h ago•74 comments

Show HN: AI agent that runs real browser workflows

https://ghostd.io
4•heavymemory•4h ago•6 comments

Show HN: I Was Here – Draw on street view, others can find your drawings

https://washere.live
55•mrktsm__•10h ago•43 comments

Show HN: VS Code Agent Kanban: Task Management for the AI-Assisted Developer

https://www.appsoftware.com/blog/introducing-vs-code-agent-kanban-task-management-for-the-ai-assi...
93•gbro3n•1d ago•47 comments

Show HN: Hopalong Attractor. An old classic with a new perspective in 3D

https://github.com/ratwolfzero/hopalong_python
21•ratwolf•4d ago•1 comments

Show HN: Hotwire Club – A Learning Community for Hotwire (Turbo/Stimulus/Rails)

https://hotwire.club
2•julianrubisch•7h ago•0 comments

Show HN: Skir – like Protocol Buffer but better

https://skir.build/
111•gepheum•1d ago•64 comments

Show HN: I wrote an application to help me practice speaking slower

https://steady.cates.fm/
2•benja123•8h ago•0 comments

Show HN: I built a real-time OSINT dashboard pulling 15 live global feeds

https://github.com/BigBodyCobain/Shadowbroker
304•vancecookcobxin•1d ago•118 comments

Show HN: I built a site where strangers leave kind voice notes for each other

https://kindvoicenotes.com
52•thepaulthomson•1d ago•26 comments

Show HN: Latchup – Competitive programming for hardware description languages

https://www.latchup.app/
2•fayalalebrun•9h ago•0 comments

Show HN: Eyot, A programming language where the GPU is just another thread

https://cowleyforniastudios.com/2026/03/08/announcing-eyot/
77•steeleduncan•2d ago•18 comments

Show HN: Zenòdot – Find if a book has been translated into your language

https://www.zenodot.app/
14•AusiasTsel•1d ago•11 comments

Show HN: sAT Protocol – static social networking

https://github.com/remysucre/satproto
3•remywang•12h ago•1 comments

Show HN: AI matchmaking from open ended dating profiles

https://sentiamor.com
3•FrenchDevRemote•4h ago•2 comments

Show HN: Husky hook that blocks Git push until you do your pushups

https://git-push.app
13•zimboy•1d ago•2 comments

Show HN: Curiosity – DIY 6" Newtonian Reflector Telescope

https://curiosity-telescope.vercel.app/
81•big_Brain69•2d ago•22 comments

Show HN: I gave my robot physical memory – it stopped repeating mistakes

https://github.com/robotmem/robotmem
18•robotmem•23h ago•3 comments

Show HN: WolfStack – Proxmox-like server management in a single Rust binary

https://wolfscale.org/
32•wolfsoftware•1d ago•3 comments

Show HN: Reviving a 20-year-old puzzle game Chromatron with Ghidra and AI

https://quesma.com/blog/chromatron-recompiled/
26•stared•3d ago•9 comments