witn vs Building In-House

Considering a DIY outcome-based billing system? Learn the hidden costs of settlement, idempotency and auditing that turn a simple project into a major build.

By George Kats

Your engineering team has a new feature request: bill customers for AI agent outcomes. The initial scope seems manageable. A new resolutions table in the database and a scheduled job to scan it should do the trick. This approach, however, often overlooks the true complexity of a reliable outcome-based billing system.

The True Scope of an Outcome-Based Billing System

The resolutions table is the visible 10 percent of the project. The submerged 90 percent is a stateful stream-processing and correctness problem that can consume quarters of senior engineering time. This is not a question of whether a competent team can build it. The question is whether it is worth the opportunity cost. The hidden work involves challenges that a simple database scan cannot solve: settlement windows, idempotency, out-of-order events, audit trails and rerating.

These are not edge cases. They are fundamental requirements for a system that customers and finance teams can trust. Building this layer correctly is a significant engineering investment. In fact, it is a product in itself. We know because we built it. Our technical deep dive on the resolution layer details exactly what you would be rebuilding, from the state machines to the concurrency controls.

Ensuring Correctness with Settlement and Idempotency

A resolved outcome is not yet a charge. It first enters a configurable settlement window, a period during which a cancellation credit or reopen event can reverse it. Only after the window closes cleanly does the outcome commit to an invoice. A simple cron job has no native concept of this waiting period. Adding it introduces significant state management complexity, turning a straightforward scan into a web of timers and conditional logic that is difficult to test and maintain.

Beyond settlement, there is the problem of idempotency. Client applications retry, workers crash and message queues redeliver. An idempotent billing system must guarantee that a customer is charged exactly once for an outcome. A naive consumer that calls a payment API directly can easily double-charge on restart, a classic dual-write problem. Correctness requires deterministic event IDs for deduplication and a transactional commit process, not a simple boolean billed column. Failures here directly damage revenue and customer trust, which is a high price to pay for what seemed like a small feature. This is a core part of the missing layer in AI agent monetization.

Data Integrity for Out-of-Order Events and Audits

Distributed event streams rarely arrive in perfect chronological order. A system that processes events based on their arrival time, such as a cron job scanning records by created_at, will silently produce incorrect results. For example, a cancellation event might arrive before the creation event it corresponds to, leading to a missed reversal. Correct evaluation must key off immutable event timestamps and be prepared to re-evaluate an outcome's state whenever a late-arriving event is received. This requires a more sophisticated model than a simple sequential process.

This historical accuracy becomes critical when a customer asks "why was I charged for this?". Your system must be able to answer with a complete audit trail. This means tracing every charge back to the specific outcome and the exact sequence of events that triggered its resolution. Retrofitting this capability onto a mutable table after the fact is exceptionally difficult. An audit trail must be an immutable, foundational part of the system's design from day one. As we've discussed before, transparent invoicing is essential for preventing billing disputes and maintaining customer confidence.

Future-Proofing with Simulation and Scale

Your pricing models and outcome definitions will evolve. Before deploying a change, you must understand its impact on revenue. This requires the ability to simulate the new rules against historical data. A proper rerating and simulation engine is a whole second system, typically an event archive paired with a fast columnar query engine. Most teams building in-house never budget for this, leaving them blind to the financial impact of their pricing adjustments. This makes it impossible to test an outcome pricing model before it goes live.

As your business grows, your billing system for AI agents must scale with it. This means handling potentially millions of concurrent outcome evaluations, each its own state machine, without race conditions or performance degradation. This is a classic distributed systems problem that requires techniques like compare-and-swap versioning to avoid slow, expensive distributed locks. A simple database table with row-level locking will not suffice at scale. Instead of hand-coding this logic, a platform approach allows you to define complex conditions in simple terms.

In-House Build vs witn at a Glance

The following table summarizes the trade-offs between a typical in-house build and using a managed platform.

ConcernIn-house resolutions table + cronwitn
Settlement windowsManual logic, complex state managementBuilt-in, configurable per outcome
Idempotency/exactly-onceRequires deterministic IDs, transactional commitsHandled automatically by the platform
Out-of-order eventsProne to silent errors if using arrival timeCorrectly evaluates based on event timestamps
Audit trailDifficult to retrofit, often incompleteImmutable log of all events for every charge
Rerating/simulationRequires a separate, unbudgeted systemBuilt-in tools for forecasting and analysis
Time to first correct invoice2+ quarters with 3-4 senior engineersHours to days
Ongoing operational loadPermanent on-call, maintenance, capacity planningManaged by witn as infrastructure

The Real Cost is Opportunity

Building this system correctly requires three to four senior engineers for at least two quarters to produce the first correct invoice. This does not include the permanent on-call load for maintenance and capacity planning. The real cost is the opportunity cost. Those are the same senior engineers who should be improving your core AI agent, which is the product your customers are actually buying.

The build vs buy billing software decision is a strategic one. Before dedicating a team to this project, engineering leaders should ask a few critical questions:

  1. Is billing correctness a core competency we want to own and maintain?
  2. Who carries the on-call pager for a double-charge incident at 2am on a weekend?
  3. What features in our core product will not get built while we are building and maintaining this billing system?

Frequently asked questions

Can't we just add a resolutions table?
A resolutions table and a cron job solve about 10 percent of the problem. They do not address the 90 percent of complexity hidden in settlement windows, exactly-once delivery guarantees, out-of-order event processing and auditable charge lineage.
How long does building this actually take?
Based on our experience, a team of three to four senior engineers will spend over two quarters building the system to the point of the first correct invoice. This is followed by a permanent operational load for maintenance, scaling and on-call support.
What is the hardest part to get right?
The hardest part is ensuring exactly-once effects through a configurable settlement window. This combination requires a robust, stateful system that can handle event retries, out-of-order delivery and concurrent updates without ever double-charging or missing a charge.
When does building in-house make sense?
Building in-house makes sense if outcome-based billing is your core product or if your requirements are so unique that no existing platform can meet them. For most companies building AI agents, buying a dedicated solution like witn is the more strategic choice.

Billing as Infrastructure Not a Project

A correct and reliable outcome resolution layer is not a feature to be shipped and forgotten. It is critical infrastructure that underpins your revenue and customer trust. witn provides this layer as managed infrastructure. Your team defines what a billable outcome looks like and sends the corresponding events. Our platform handles the complex work of resolving that outcome into a correct, settled and fully auditable charge.

Focus your engineering talent on building a better agent, not a billing system. Read the docs.

The complete monetization playbook

AI Agent Monetization: The Complete Guide report cover

How to price, verify and bill the work your AI agent delivers. A practical playbook for founders, product leads and engineers, from choosing a pricing model to operating outcome-based billing in production. 17 pages, free download.

On this page