Back to technology news
Programming & Development

Cloudflare introduces Spend Management beta for Workers and Durable Objects

Spend controls have been among the most requested features from developers building on the Cloudflare platform, where more than 10 million creators now work. Although usage notifications and budget alerts have existed for paid plans, informing users is not the same as controlling usage. The new Spend Management beta lets any pay-as-you-go customer set spending thresholds and choose to have Cloudflare pause activity when limits are reached, thus avoiding unexpected bills from unplanned usage. Today the feature launches for Workers and Durable Objects, with more products to follow. Users can configure limits, alert thresholds, and notification emails through the dashboard, cf CLI, or REST API, and the system will enforce a blocking policy that pauses the product once the cap is hit.

The implementation relies on a two-stage metering pipeline that aggregates raw usage measurements close to the source before they reach the downstream Rating Engine. In the first stage, each metering parser converts raw events into usage measurements and combines matching measurements into typically one-minute windows. A separate service then merges those first-stage partial aggregates over typically five-minute windows in the second stage, further reducing volume before downstream processing. This approach reduces raw event volume early so the downstream engines process only accumulated usage, making the system practical at Cloudflare scale. The pipeline also archives consolidated aggregates for later analytics and reconciliation.

The Usage Engine translates aggregated measurements into standardized usage records containing account, usage window, metric, quantity, and relevant dimensions, mapping product-specific meters into supported metrics. Processing is partitioned by account so each account's usage and subscription information meet in the same place, allowing the engine to maintain accumulated usage and apply included allowances without cross-partition coordination. Each partition retains a local state for fast access and a durable write-ahead logging changelog on disk, providing less cross-partition coordination, consistent pricing, parallel processing capability, and recoverability after failures. The engine handles out-of-order arrival of usage and subscription data by retaining usage as pending until pricing information becomes available, ensuring unpriced usage is not treated as free.

The Rating Engine is the core of Spend Management, translating usage into monetary value by combining usage records, subscription information, and pricing rules from a product catalog database. It first applies the account's included allowances before pricing any excess usage, calculating accumulated spend rather than rounding and charging per request independently. Once accumulated spend is calculated, the engine evaluates whether warning or blocking thresholds have been reached and triggers reporting, dashboard display, and email alerts via the Cloudflare Email Service. Critically, the Rating Engine does not sit in the request path or directly reject requests; instead, policy decisions are propagated asynchronously to Quicksilver, Cloudflare's internal key-value store, which distributes caps globally to all nodes. Runtimes pick up the cap during periodic refresh and begin rejecting capped invocations using local state, so requests never wait on the Rating Engine.

Any pay-as-you-go customer can start using Spend Management immediately for Workers and Durable Objects, with additional products to follow. The system currently supports setting spending limits, specifying notification emails, and configuring one or more alert thresholds. When a limit is reached, new invocations of the capped product are rejected; however, only customer-code invocations that incur costs are paused, while static assets and other non-cost-incurring operations continue. To resume service, users can raise the limit above current cycle spend, disable or delete the blocking policy, or wait until the next billing cycle when the existing block expires. The dashboard shows current billing cycle costs in near real time under 10 minutes and maintains an audit log of who changed limits and when caps were reached.

Looking ahead, Cloudflare plans to expand Spend Management to many other products and primitives, aiming for enforcement under a minute rather than the current near-real-time benchmark. The company also envisions agent and application-based budgets, allowing developers to monitor aggregated costs of specific applications or AI agents that consume compute, database, and storage resources across products. Metadata from agent calls would carry through the pipeline to the Rating Engine, enabling cost attribution and pausing of application or agentic tasks without interrupting unrelated applications. This launch represents a first step toward making spend controls a normal part of building on Cloudflare alongside deploying code and monitoring applications.

Source credits

By Celso Martinho from Cloudflare Blog. Edited by SetuGeo.

More technology news

Browse all technology news