.png)
Billing System Architecture vs. Entitlements Explained
Billing system architecture manages invoices and payments. Entitlements control product access and limits. See how both layers fit into a modern software stack.
Learn how usage metering works across ingestion, aggregation, and enforcement. Covers real-time tracking and scaling for production systems.
.png)
Usage metering works fine until an AI agent starts generating 3,000 events per minute across a multi-step workflow and the pipeline falls behind. Enforcement is reading stale state. A customer blows past their limit. The metering layer catches up an hour later, by which point the overage has already been charged.
This guide covers how usage metering works, where pipelines break under AI workloads, and what the infrastructure needs to handle it at scale.
Usage metering is the process of tracking and converting product usage into measurable data that can be billed or enforced.
It captures, transforms, and aggregates raw consumption into structured metrics. Billing then uses those metrics to apply pricing and generate invoices.
For engineering teams, usage metering is the pipeline that records what was consumed, by whom, and when. Without it, there is no reliable way to enforce limits, calculate charges, or provide visibility into usage.
Usage metering works by capturing raw usage events, transforming them into measurable metrics, and applying pricing rules to determine charges.
The pipeline has three stages, each adding structure before data reaches billing or enforcement. The table below maps each stage to its infrastructure requirement:
Ingestion collects raw telemetry such as API calls, tokens consumed, storage written, and agent actions completed.
This data arrives in different formats and volumes, often at very high scale. At this stage, the system standardizes and cleans the data so it can be processed consistently.
Metering converts that normalized event stream into billable, aggregated metrics.
For example, a storage system tracks usage over time and converts it into billable units like GB per month by applying aggregation logic.
Rating applies pricing rules to those metrics to calculate charges. This includes handling tiered pricing, discounts, credits, and overage fees.
The aggregation method depends on what you are measuring:
Choosing the wrong aggregation method leads to incorrect billing and makes reconciliation difficult.
Real-time and batch usage metering differ in how they process events and how they support enforcement in a system.
Batch metering processes events at set intervals such as hourly, daily, or at the end of a billing period. It works for billing reconciliation where accuracy matters more than speed, but it can’t enforce limits before usage exceeds them.
Real-time usage metering processes events as they arrive and updates usage state immediately. This allows the system to check balances, validate entitlements, and allow or block actions before they run.
For AI products where a single agent session can generate thousands of events in minutes, batch metering creates an enforcement gap. By the time the pipeline processes the events, the usage has already happened, and the overage has already posted.
Real-time usage metering requires a pipeline that can handle bursts of events, a low-latency layer for usage reads, and fallback behavior when parts of the system are unavailable.
Usage metering is harder in AI products because consumption is more granular, costs are tied to infrastructure, and workflows span multiple steps.
AI workloads introduce three challenges that standard SaaS systems do not face:
These factors make attribution more complex, since usage is spread across multiple steps within a workflow. The system needs to track consumption at each step so the total reflects what actually happened behind a single user action.
A single event at the request level misses that detail when usage is distributed across multiple internal operations.
Usage metering tracks what was consumed, while enforcement uses that data to decide what can happen next in real time. These two layers serve different roles in the system:
Usage-based billing tools focus on metering. They capture events, count usage, and pass that data to billing systems for invoicing. Their role centers on accurate usage reporting over time, while enforcement happens separately at request time.
Enforcement lives in the entitlements layer. It defines what a customer can consume based on their plan and current usage, including limits, current balance, and what happens when those limits are reached.
When usage approaches a limit, enforcement acts before the request completes. Metering records the outcome after the fact. Both layers work together, but they solve different problems.
In-house usage metering starts to break when systems move beyond simple counters and need to handle shared usage, real-time updates, and changing plans.
Most teams build a basic metering setup early on. A credits table and a decrement function work at low scale, and the decision to build in-house makes sense at that stage.
The issues show up as usage grows and the system needs to stay consistent under load:
At this stage, the problem shifts from tracking usage to maintaining consistent state across the system.
Enterprise customers make this harder. They need usage tracked and enforced independently across teams, departments, products, and agents within the same organization.
Most in-house systems were never designed for that cardinality and get retrofitted under deadline when the first enterprise contract demands it.
Stigg handles this natively per-agent, per-team, and per-department enforcement without retrofitting.
Usage metering works only when the system can act on that data before a request completes.
Accurate usage tracking alone does not control behavior. The system needs to read current usage, resolve entitlement state, and decide whether to allow or block the action in the request path.
That decision has to happen locally to keep latency predictable. A remote call on every request adds delay that compounds under load.
At production scale, systems handle this by:
For teams with data residency requirements, the enforcement layer needs to run inside their own infrastructure. A BYOC deployment keeps entitlement data within the VPC and removes any dependency on external uptime for read-path decisions.
If the upstream service loses availability, the local cache keeps enforcement running without falling back to open access or blocking all requests.
This structure keeps enforcement fast and consistent while usage continues to change in real time.
Stigg is the usage runtime for AI products. Entitlements, credits, usage limits, and spend governance run synchronously in the request path before compute is consumed.
For engineering teams building or rethinking this layer:
You don't need to adopt the full stack since each component works independently, so teams can start with credits or enforcement and expand from there.
When metering and enforcement are separated correctly, pricing changes stop being engineering work. Usage decisions stay fast under load, and the audit trail is already there. If that's not where your system is, see how Stigg’s infrastructure works.
The main difference between usage metering and billing is that metering records what was consumed while billing applies pricing rules to generate invoices. Metering runs continuously as usage occurs. Billing runs on that data after the fact to calculate charges and process payments.
The main difference between real-time and batch usage metering is when events are processed. Batch metering processes usage at fixed intervals and works well for billing reconciliation, but cannot enforce limits before they are exceeded.
Real-time metering processes events as they arrive, which allows the system to check balances and block requests before usage completes.
Usage metering in AI products tracks token consumption, agent actions, and multi-step workflow costs at the event level.
Because a single request can vary widely in cost depending on model type, input length, and reasoning mode, the metering layer needs to attribute usage at each step rather than recording a single event at the request level.
Usage metering breaks under concurrent load when multiple sessions draw from a shared balance simultaneously and the system lacks atomic operations to prevent race conditions.
Without atomic debit operations against an append-only ledger, two concurrent requests can read the same balance before either commits, both go through, and the balance goes negative without triggering a hard limit.
Real-time usage metering requires a high-throughput ingestion pipeline, a low-latency read layer for enforcement decisions, and fallback behavior when parts of the system are unavailable.
At scale, this means keeping entitlement state in a local cache so checks resolve without a network call on every request, with a configurable timeout to prevent upstream latency from cascading into the application.