
Multi-Tenant Architecture: 3 Models & 8 Best Practices
Learn how multi-tenant architecture works, compare database isolation models, and explore six components & eight best practices for shared infrastructure.
Usage metering explained for engineers: how events become metrics, what to meter, real-time vs. batch pipelines, and where metering breaks at scale.
Usage metering works fine until an AI agent fans out across a multi-step workflow and the pipeline falls behind. Enforcement reads stale state, a customer sails past their limit, and by the time the meter catches up an hour later, the overage has already been charged.
Most of that damage happens in the plumbing: how events get ingested and deduplicated, how they're aggregated, and how quickly the current number reaches the code deciding whether the next request runs.
What follows is the full usage metering pipeline, from the event your app emits to the balance your enforcement check reads, along with how to choose what to meter, what customers need to see, and where in-house builds tend to run out of road.
Usage metering is the process of capturing product usage as events, aggregating those events into measurable quantities, and making the totals available for enforcement, billing, and reporting.
For engineering teams, usage metering is the pipeline that records what was consumed, by whom, and when. API calls, tokens, GPU seconds, storage, and agent actions all qualify, as long as each unit can be traced back to a customer.
Without it, there's no reliable way to enforce limits, calculate charges, or show customers what they've used.
One quick disambiguation, since the term gets shared: software usage metering is unrelated to the smart meters utilities install for electricity, gas, or water. Both measure consumption, but the data and the stack have almost nothing in common.
Usage metering works by capturing raw usage events, rolling them up into aggregated metrics, and handing those metrics to the systems that price, enforce, or display them.
The pipeline has three stages, and each one adds structure before the data reaches billing or enforcement:
| Stage | What it does | Engineering requirement |
|---|---|---|
| 1. Ingestion | Captures raw events from your app and infrastructure | High-throughput intake, validation, deduplication |
| 2. Metering | Aggregates events into per-customer metrics | Aggregation logic, real-time or batch processing |
| 3. Rating | Applies pricing rules to metered totals | Pricing engine, credit handling, overage detection |
Ingestion collects raw telemetry such as API calls, tokens consumed, storage written, and agent actions completed. Each event needs a handful of fields to be useful downstream:
Dimensions are cheap to add on day one and painful to backfill on day 300, so capture more than you think you'll need.
The two failure points at this stage are retries and late arrivals. Clients retry after timeouts, so without an idempotency key the same event gets counted twice. Events that arrive out of order need a clear rule for which aggregation window they belong to.
Metering converts the cleaned event stream into aggregated metrics per customer, per feature, and per period.
A storage service, for example, samples usage over time and rolls it up into billable units like GB per month.
The aggregation method depends on what you're measuring:
Choosing the wrong aggregation method leads to incorrect bills and makes reconciliation painful, because every disputed invoice turns into a debate about what the number was supposed to mean.
Rating applies pricing rules to the metered totals to calculate charges, including tiers, included allowances, credits, discounts, and overage fees.
This is where metering hands off to billing, which brings its own edge cases like proration and invoice timing. Stigg's guides to metered billing and event-based billing cover that side in depth.
Real-time and batch usage metering differ in when they process events, and that timing decides whether the system can enforce anything.
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 stop usage before a limit is exceeded.
Real-time metering processes events as they arrive and updates usage state immediately. That lets the system check balances, validate entitlements (what each customer's plan, add-ons, and credits allow them to use), and allow or block an action before it runs.
| Approach | How it works | What it enables | Limitation |
|---|---|---|---|
| Batch | Processes usage at fixed intervals | Accurate billing and reconciliation | Can't enforce limits before usage occurs |
| Real-time | Processes events as they happen | Pre-request checks and enforcement | Higher infrastructure cost and complexity |
For AI products, where a single agent session can generate thousands of events in minutes, batch metering creates an enforcement blind spot. By the time the pipeline processes those events, the usage has run and the overage has posted.
In practice, production systems usually run both: a hot path that aggregates in short windows for enforcement, and a cold path that stores every raw event for audits, disputes, and rebuilding totals when a bug slips through.
Choose a usage metric that customers already understand, can estimate in advance, and that moves with your cost of serving them. When one unit can't do all three, use more than one meter.
This is a metering design decision as much as a pricing one, because the unit you pick decides which events you emit, which dimensions they carry, and what your enforcement layer checks on every request.
API calls, messages, documents processed, and minutes of audio all pass this test. If you have to explain the unit before anyone can buy it, your support team will be explaining it forever.
A customer planning next quarter's budget should be able to guess their usage within a reasonable range. Tokens are precise but hard for most buyers to forecast, which is one reason many AI products sell credits that convert to tokens behind the scenes.
If one request can cost far more than another (long context windows, reasoning modes, and bigger models all do this), a flat per-request meter hides margin risk. Meter the cost driver directly, or capture it as a dimension so you can weight it later.
An AI product might meter seats for access, credits for model usage, and storage on its own line. For API products, the API metering decisions (what to measure, where to capture it, and how to enforce it) follow the same logic at the endpoint level.
Usage metering shows up anywhere consumption varies from one customer to the next. Here's what typically gets metered across product types:
| Product type | What gets metered | Typical aggregation |
|---|---|---|
| SaaS | Active users, documents, workflow runs | Count unique, count |
| API products | Requests by endpoint or tier | Count |
| Cloud infrastructure | Compute hours, storage, data egress | Sum, average over time |
| LLM APIs | Input and output tokens by model | Sum |
| AI agents | Tasks, tool calls, credits burned | Sum, count |
| Communications | Messages sent, call minutes | Count, sum |
Model providers are the clearest case. OpenAI's API pricing lists separate rates for input, cached input, and output tokens on each model, with higher rates for long context, so every request has to be metered by model, token type, and context length before it can be priced.
Agents push this further, because one user-facing task fans out into many model calls and tool executions that all need to roll up to the same customer and task. For more patterns, see these usage-based pricing examples.
Usage metering lets price track the value customers get, so revenue grows as they use more and your costs and revenue move together.
Every one of these benefits depends on a meter that finance, engineering, and customers all trust, so it pays to get the event data clean before layering usage-based billing on top.
Usage metering is harder in AI products because consumption is more granular, every unit carries real infrastructure cost, and a single user action can span many steps.
AI workloads add three challenges that most SaaS metering never had to handle:
The system needs to track consumption at each step so the total reflects what happened behind a single user action. A single request-level event misses that detail when usage is spread across internal operations.
Usage metering records what was consumed, while enforcement uses that data to decide what can happen next, in real time. The two layers play different roles:
| Layer | What it does | When it runs | Purpose |
|---|---|---|---|
| Metering | Captures and aggregates usage events | After usage occurs | Billing, reporting, analytics |
| Enforcement | Applies limits and decides allow or block | During the request | Controls usage and prevents overage |
Usage-based billing tools focus on metering. They capture events, count usage, and pass totals to billing systems for invoicing, with enforcement handled somewhere else at request time.
Enforcement lives in the entitlements layer. It knows what a customer is allowed to consume based on their plan, add-ons, credits, and current usage, and what should happen when they reach a limit.
This is the failure mode from the top of this article. The looping agent above only overspends because the check reads a number the pipeline hasn’t updated yet.
The check also has to be fast, so it can't make a remote call on every request without adding latency that compounds under load. Systems that keep latency predictable at production scale tend to:
For teams with data residency requirements, the enforcement layer has to run inside their own infrastructure. A bring-your-own-cloud (BYOC) deployment keeps usage and entitlement data within the VPC and removes any dependency on external uptime for read-path decisions.
The biggest usage metering challenges show up on two sides: the business has to define units and live with variable revenue, and engineering has to keep usage state correct under load.
Most teams build a basic metering setup early on, and that's a reasonable call. 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 has to stay consistent under load:
At this point the problem shifts from tracking usage to keeping state consistent across the whole system.
Enterprise customers make it harder still. They need usage tracked and enforced independently across departments, teams, users, and agents in one organization, a cardinality most in-house systems weren't designed for.
It usually gets retrofitted under deadline when the first enterprise contract demands it.
Customers should be able to see their current usage in real time, get warned before they hit a limit, and pull usage data into their own systems.
Datadog's Usage Metering API is a good reference for exports: customers pull hourly, daily, and monthly usage, delayed by up to 72 hours. That's plenty for cost reporting and too slow to warn anyone before they hit a limit, which is why exports work best alongside a live view.
All three should read from the same metered data your enforcement layer uses. If the dashboard says 80% and the enforcement check says 100%, customers will notice before you do. For AI products, this visibility is part of AI usage control, alongside the limits themselves.
Accurate usage metering is the foundation, but a meter that only reports after the fact leaves the expensive question unanswered: should this request run?
Metering tells you what happened. Stigg decides what's allowed.
Stigg is the usage runtime for AI products. It works alongside your billing provider and runs real-time metering, credits, entitlements, and governance in one enforcement layer that sits in the request path.
With Stigg, engineering teams can:
You don't need to adopt the whole stack, since each component works on its own and teams often start with credits or enforcement and expand from there.
When metering and enforcement read from the same real-time state, pricing changes become configuration work, and the audit trail is already there when finance asks for it.
If your usage pipeline is starting to creak under agent traffic, talk to a human about your stack, or start with the AI quickstart in the docs.
The difference between usage metering and billing is that metering records what was consumed, while billing applies pricing rules to that data to generate invoices. Metering runs continuously, and billing runs on the metered totals after the fact.
Software metering is the practice of tracking how software is used, by whom, and how much. It originally meant monitoring application use for license compliance. In SaaS, API, and AI products, it usually means usage metering for enforcement, billing, and reporting.
A common example of usage metering is an LLM API counting input and output tokens per model for each customer. Each request emits an event with the customer ID, model, and token counts, the pipeline sums them per billing period, and the totals drive both limits and invoices.
The difference between real-time and batch usage metering is when events are processed. Batch metering processes usage at fixed intervals and works for billing reconciliation, while real-time metering processes events as they arrive so the system can block requests before a limit is exceeded.
Usage metering breaks under concurrent load when multiple sessions draw from a shared balance at the same time and the system lacks atomic operations. Two requests can read the same balance before either commits, both go through, and the balance goes negative without triggering a hard limit.