B

Glossary

Billing Engine

A billing engine is the component of a billing system that turns metered usage, contract terms, and pricing rules into invoice line items. The engine handles rating, proration, discounts, credits, and tax application, then hands a finalized invoice to a payment provider for collection.

Key Takeaways

  • The engine computes what's owed; the gateway moves the money. Confusing them is why teams assume Stripe or Razorpay already solved billing.

  • An engine has to be deterministic. The same inputs must produce the same invoice every run, or a corrected reissue rewrites history.

  • Building one in house is measured in months, not sprints. Simplismart spent 1.5 to 2 months building a custom engine on top of Lago before replacing it.

  • The maintenance cost outlasts the build. Simplismart burned 20 to 30% of a developer's daily bandwidth keeping theirs running, and reclaimed 30% of daily engineering bandwidth after moving off it.

  • Engine latency becomes product latency once entitlement checks sit in the request path, which is why sub-100ms rating matters for real-time gating.

What does a billing engine actually do?

It resolves usage and contract terms into priced line items, in a fixed sequence, for every subscription in every cycle.

The stages inside a working engine:

Stage

What it produces

Aggregation

A billable quantity from raw usage events

Rating

A price applied to that quantity under the customer's plan

Proration

Adjusted amounts for partial periods and mid-cycle changes

Credit application

Balances drawn down against the amount owed

Discounting

Coupons, volume tiers, and negotiated overrides applied in order

Tax calculation

Jurisdiction-correct tax on the taxable subtotal

Invoice assembly

Line items, subtotals, and totals on a finalized document

Order matters and isn't obvious. A discount applied before a credit gives a different total than the reverse, and both are defensible, so the engine encodes whichever your contracts assume.

How is a billing engine different from a payment gateway?

The engine decides the amount; the gateway collects it. They sit next to each other and share almost no responsibility.

Concern

Billing engine

Payment gateway

Core job

Calculate what's owed

Move money

Inputs

Usage events, plans, contracts

An amount and a payment method

Knows about

Meters, tiers, credits, proration, tax

Cards, bank rails, currencies, authorization

Output

An invoice

A settled or failed transaction

Failure mode

A wrong number on a correct invoice

A correct number that fails to collect

A gateway handed a wrong amount charges it successfully, which is the expensive version of this mistake. Nothing downstream catches it, so it surfaces weeks later as a complaint or audit finding.

What does it take to build a billing engine in house?

More than the invoice generation most teams scope for, because the hard parts are corrections and edge cases, not the happy path.

What has to exist before it's production-grade:

  • Deterministic recomputation against historical pricing, so re-running a closed period reproduces the original invoice at the rate that applied then

  • Idempotent ingestion, because duplicated events become duplicated charges

  • Proration in every plan-change direction, including downgrades and mid-cycle cancellations

  • Multi-currency and per-jurisdiction tax handling

  • An audit trail on every pricing and contract change

Simplismart spent 1.5 to 2 months building a custom engine on top of Lago, then lost 20 to 30% of a developer's daily bandwidth maintaining it, with the system breaking under heavy load.

How do teams choose a billing engine?

They start from the pricing they'll need in 18 months, not today's, because migrating an engine mid-contract is the expensive path.

Flexprice is enterprise-grade, open source usage based billing infrastructure for AI and SaaS companies. It can be deployed in your own VPC, on-prem, or on Flexprice's managed cloud. It rates usage at under 60ms P99, keeping entitlement checks viable in the request path, and Simplismart reclaimed 30% of daily engineering bandwidth plus $145K+ in annual savings after replacing their in-house engine with it. Rating, proration, credits, and tax live in Billing and Invoicing rather than in application code.

"If billing doesn't work, we don't make money. Flexprice lets us focus on the core business instead of building billing as a second product." - Shubhendu Shishir, Head of Engineering, Simplismart

The engine internals and API surface are documented at docs.flexprice.io if you want to compare them against a build.

Related reading

Further reading on building against buying an engine:

FAQ

Is a billing engine the same as a billing platform?

No. The engine is the calculation layer; the platform is the engine plus the portal, dashboards, integrations, dunning, and reporting around it. Vendors use both interchangeably, so the test is whether the product only computes invoices or runs the workflows too.

Can Stripe act as a billing engine?

For straightforward subscriptions, yes. Stripe Billing handles recurring invoicing and simple metered charges, and for a seat-based product that's often enough. The constraint appears as pricing gets more complex: hybrid models combining credits, committed usage, and metered overage on one invoice, or contract structures that ramp across years, are where teams typically add a dedicated engine alongside the gateway.

Does a billing engine need to run in real time?

It depends on whether anything in your product blocks on it. Invoice generation can run overnight in batch without anyone noticing. Entitlement checks and credit balance lookups can't, because their latency becomes your API's latency. Most teams need real-time reads against near-real-time aggregation, not real-time invoicing.

What breaks first in a homemade billing engine?

Corrections. Teams ship the happy path quickly. What breaks is the first time a rate was wrong and a closed invoice has to be reissued, because that needs historical pricing, deterministic recomputation, and an audit trail most in-house builds never scoped.

Back to glossary

Get Instant Feedback on Your Pricing | Join the Flexprice Community with 400+ Builders on Slack

Join the Flexprice Community on Slack