Menu
Cloudflare Blog·November 13, 2026

Designing a Global Spend Management and Usage Metering Architecture at Scale

Cloudflare's architecture for their Spend Management system utilizes a two-stage metering pipeline, account-partitioned processing with Write-Ahead Logging (WAL), an independent Rating Engine, and asynchronous cap enforcement via a global key-value store to handle cost controls for millions of developers.

Read original on Cloudflare Blog

Architectural Overview of Spend Management

Building a global spend control system requires balancing data ingestion scale, processing latency, and eventual enforcement consistency. Cloudflare's Spend Management architecture decouples high-frequency telemetry collection from the critical request path, ensuring that enforcement checks never introduce latency into user workloads.

The Two-Stage Metering Pipeline

Transporting and processing raw usage events directly from the edge to a rating engine would overwhelm downstream infrastructure. To solve this, Cloudflare implements a two-stage aggregation pipeline close to the source:

  • Stage 1 (Metering Parsers): Raw events are parsed and grouped into typically one-minute buckets, reducing event volume immediately near the source.
  • Stage 2 (Merge Service): A separate service merges first-stage partial aggregates over five-minute windows, archiving consolidated data to a durable dataset for analytics and auditability.

Account-Partitioned Processing and the Rating Engine

The Usage Engine partitions workloads by account, allowing an account's usage metrics and subscription details to be processed together without cross-partition coordination. Each partition maintains local state alongside a durable Write-Ahead Log (WAL) on disk, guaranteeing recoverability and independent parallel scaling.

ℹ️

Handling Independent Data Streams

Usage records and subscription updates arrive via independent asynchronous streams. If usage arrives before subscription context, the Rating Engine retains it as pending rather than prematurely pricing it as free, ensuring robust fault tolerance against webhook failures or delivery delays.

Asynchronous Cap Enforcement

To protect request latency, the Rating Engine stays completely out of the hot request path. Once a spending cap or threshold breach is calculated, the policy service pushes the update to Quicksilver, Cloudflare's distributed key-value store. Edge runtimes periodically poll this local state to reject over-budget invocations asynchronously.

meteringrate-limitingdistributed-systemsedge-computingscalingarchitecturebilling

Comments

Loading comments...

Want the fundamentals behind stories like this? Take the free System Design Academy course with certificate.