Batch aggregation closes a billing period at midnight, runs the event totals, and generates an invoice. The customer gets a bill at the end of the month. This works, and it is operationally simpler than the alternative. The problem is that by the time the bill arrives, there is no ability for the customer to have stopped anything. An agent that ran 400 percent over its expected usage did so, finished, and the bill reflects the completed work. Spending controls require knowing the current usage total, which batch aggregation by definition does not provide until the batch runs.
Real-time aggregation maintains a continuously updated balance per customer. Every event that arrives at the metering endpoint increments the running total immediately. When a customer's dashboard shows their usage, it is current to within seconds. Threshold alerts fire when the running total crosses a configured limit. This requires more infrastructure than batch but enables product features that batch cannot support.
What Batch Gets Right
A batch aggregation architecture processes events asynchronously from ingestion. Events are written to a durable store (a queue or a raw event table), and an aggregation job runs on a schedule to compute totals. The aggregation job can handle out-of-order events trivially because it scans the event window at computation time rather than maintaining incremental state.
Out-of-order handling is one of the genuine advantages of batch over real-time. In distributed agent systems, events from concurrent sub-agents may arrive in an order that does not match their logical sequence. An event with occurred_at of 2:58 PM might arrive after an event with occurred_at of 3:04 PM. Batch aggregation handles this naturally: the job looks at all events in the window and sums them regardless of arrival order. Real-time aggregation that applies events immediately to a running total can produce temporarily incorrect balances when events arrive late, requiring compensating mechanisms to correct.
Batch is also simpler to reason about from an accounting correctness perspective. The aggregation runs once, deterministically, over a closed event set. If the result is wrong, you can rerun it against the same data and get the same result. Debugging is tractable.
What Real-Time Enables
Spending controls: a hard limit that stops billing events from being counted once a customer's running total exceeds a threshold. Soft limits that alert the customer but allow continued operation. These require a queryable current balance that is accurate within seconds.
Usage dashboards: a customer-facing view of current period consumption that refreshes in real time. For customers running large pipelines, the ability to see usage accumulate in real time lets them monitor for runaway workflows before the end of the billing period.
Anomaly detection: identifying unusual usage patterns early. If a customer's daily consumption is running three times their historical average, a real-time aggregation system can surface that signal within minutes. A batch system surfaces it at the next batch run, which may be hours later.
The Hybrid Approach
The architecture we use at Paygentic is a combination: events are written to a fast Redis-backed counter for real-time balance queries, and simultaneously written to a durable event store for batch invoice generation. The Redis counter provides the current balance for dashboards and spending controls. The batch job over the durable event store provides the authoritative invoice at billing period close.
The two systems can diverge. If a Redis counter is lost due to a node failure, the authoritative record in the durable store is used to reconstruct it. The invoice is always generated from the durable store, not from the Redis counter. This separation means a failure in the real-time layer does not affect billing correctness. It does temporarily degrade the customer dashboard experience, which is a product issue rather than a billing integrity issue.
The key design principle is that the durable event store is the source of truth for billing. The real-time layer is a cache of derived state for product features. They are both populated on every ingest write, but they serve different consumers with different consistency requirements. Conflating them by using a single system for both leads to either weakened billing correctness guarantees or weakened real-time freshness, depending on which requirements you sacrifice.
Choosing the Starting Point
For a product at early stage, batch aggregation is the pragmatic starting point. It is correct, debuggable, and simpler to operate. The real-time layer can be added when the product requirements demand it, because adding a Redis counter to an existing durable event store is an additive change, not a rearchitecture.
The mistake to avoid is choosing batch aggregation because it is simpler, then building product features that assume real-time balance availability. Usage dashboards that query the batch aggregate are a product limitation that customers will notice and ask about. The moment you commit to a customer-facing usage dashboard, you have committed to the real-time layer. Building the dashboard first against batch data creates a migration that would have been simpler to avoid.