Skip to the yard
Waxsealai

Cloudflare Spend Management Adds Usage Caps for Workers and Durable Objects

Shipped
Shipper
Celso Martinho
Readers
478

Pay-as-you-go customers can set spend limits that pause billable Workers and Durable Objects activity, with usage estimates updated in under 10 minutes.

Cloudflare Spend Management Adds Usage Caps for Workers and Durable Objects

Cloudflare’s new Spend Management feature gives pay-as-you-go customers a way to stop eligible usage when costs reach a chosen limit. The beta currently covers Workers and Durable Objects, extending billing tools beyond alerts: customers can configure a blocking cap that pauses billable activity once it is reached.

That distinction matters for services whose usage can rise unexpectedly. Notifications and budget alerts can flag spending, but they leave the response to the customer. Spend Management can apply the response automatically. It can be used alongside AI Gateway spend limits, which support per-user and per-model budgets for AI requests routed through the gateway, including requests to Workers AI and other providers.

Setting a cap and seeing its effect

Customers can configure Spend Management through the dashboard, the cf CLI, or the REST API. In the dashboard, the controls are under Account, Billing, and Spend limits. After enabling controls for a supported product, a customer sets a spending limit, can provide an email recipient, and can add one or more alert thresholds.

When evaluated spending reaches a configured threshold or the cap, Cloudflare can send an email notification. Reaching the cap also activates a blocking policy and pauses the product automatically. The dashboard displays estimated costs for each supported product in near real time, with updates taking under 10 minutes. Its overview indicates which products have limits and thresholds; an audit log records who changed a limit and when, as well as when a cap was reached.

The billing period follows the paid subscription, rather than the date a Worker is deployed or a cap is created. A subscription that starts on October 10 generally runs through November 10, for example. That timing affects when accumulated spending resets and when a blocking policy expires.

The API can create a policy with a product identifier, a threshold in cents, an action, and an optional notification email. Cloudflare’s example sets a Workers cap at 10,000 cents, or $100, and uses the usage_block action. The CLI supports listing, creating, retrieving, updating, and deleting spend policies, plus viewing policy audit and activity records. This gives teams a route to manage caps programmatically as part of account operations.

A cap blocks new customer-code invocations that incur costs. For Workers, that includes Cron Trigger and Queue consumer invocations; static assets continue to be served. To restore service after a cap takes effect, a customer can raise the limit above current cycle spending, disable or delete the blocking policy, or wait for the next billing cycle, when the existing block expires.

How usage becomes a spending decision

The central engineering challenge is turning activity distributed across Cloudflare’s network into a timely, consistent cost estimate and then making a blocking decision available across that network. The system is designed to keep raw events out of the downstream pricing path wherever possible.

Each invocation generates product-specific measurements, such as requests, CPU time, execution duration, or storage operations. Sending every raw event directly to the rating system would create unnecessary processing load. Instead, a two-stage metering pipeline aggregates measurements near their source. Parsers first group matching events into typically one-minute buckets. A separate service merges partial aggregates over typically five-minute windows, reducing the volume further before forwarding usage to the Usage Engine. Consolidated aggregates are also archived for later analysis and reconciliation.

The Usage Engine converts those aggregates into standardized usage records. Each record identifies an account, a usage window, a metric, a quantity, and relevant dimensions. Processing is partitioned by account, keeping that account’s usage and subscription data together. This lets the system track accumulated usage and apply included allowances without coordinating across pricing processors for each update.

Each partition keeps local state for fast access and a durable write-ahead log on disk. Keeping account state together supports consistent pricing, while separate partitions can process different accounts in parallel. The durable log also lets replacement processors rebuild state and resume work after a failure.

The Rating Engine combines usage records with subscription details and pricing rules. The relevant inputs include the billing period, plan changes, rates, included allowances, and rounding rules. Its task is to estimate how much an account has spent based on what it consumed and the terms of its subscription.

Usage and subscription updates arrive on separate streams and may reach the engine out of order. If usage arrives before the subscription information needed to price it, the engine holds that usage as pending and revisits it when the missing information becomes available. This also helps the system recover when subscription data is delayed, including after a failed webhook, instead of treating unpriced usage as free.

Spend is calculated on accumulated usage. For example, CPU time may be covered by an included allowance before any excess is priced; one million CPU milliseconds does not necessarily create an additional charge. The engine applies the product catalog’s rates and rounding rules to the accumulated quantity rather than rounding and pricing each request independently. It then evaluates warning and blocking thresholds, reports estimated charges through the dashboard and APIs, and sends email alerts when configured.

Blocking happens outside the request path

The Rating Engine doesn’t directly reject customer requests. After policy evaluation, a policy service sends the cap to the runtime configuration service and Quicksilver, Cloudflare’s globally distributed key-value store. The cap propagates asynchronously to network nodes. Runtime systems pick it up during periodic refreshes and begin rejecting capped invocations or operations once the updated configuration arrives.

That design keeps the rating calculation out of the request path: a customer request doesn’t need to wait for the engine to calculate spend. Enforcement instead relies on local runtime state, using Cloudflare’s existing account-limit architecture to distribute the blocking policy. Because updates propagate asynchronously, the displayed estimate and the application of a cap are not instantaneous. Current cost information is available in under 10 minutes, and the company says it aims to reduce the measurement-to-enforcement interval, potentially to under a minute.

Expanding budgets across products and applications

The beta starts with Workers and Durable Objects, but Cloudflare says it plans to add caps for more products and primitives. The system is designed to let product teams add support, though no specific rollout schedule or additional products are named.

Product-level controls can leave a gap for applications that combine several services. A Worker might use R2 or Workers AI, for example, and teams may want a budget for the combined application rather than separate caps that affect other applications using the same products. Cloudflare is exploring application-level attribution and controls to address that need.

AI agents present a related challenge. A budget for AI requests routed through AI Gateway can limit those requests, but a task may also consume compute, database, and storage resources. Cloudflare’s stated direction is to carry tags for agent calls from runtime systems through the usage and rating pipeline. That could let customers attribute costs across products and pause a particular application or agent task without interrupting unrelated workloads. These are planned capabilities, not part of the current product scope.

For now, the practical step is to configure limits for Workers and Durable Objects and decide which alerts and automatic blocking behavior fit the workload. Cloudflare’s billing documentation describes the available controls. The key measure to watch as the beta develops is how quickly usage estimates and distributed caps catch up with activity, alongside the range of products and cost dimensions the system can cover.

Source: Celso Martinho · blog.cloudflare.com

Same vesselRelated cargo