Usage Metering and Billing Engine for API Products
A developer-facing web service that ingests usage events from API and SaaS products, aggregates them into billable metrics, applies tiered and package pricing, and produces invoices and customer usage dashboards. An advanced final year project in backend systems, correctness and developer tools.
Advanced
Needs a team, real planning, and a supervisor who knows the area.2 semesters · 3 students
8 to ship
3 optional extrasSuggested stack
What you should ship
- Event ingestion API with API keys, batch endpoints and idempotency keys so retried events are never double counted
- Billable metric definitions: count, sum of a property, unique count and maximum, filtered by event properties
- Pricing plans with flat, per-unit, graduated tiers, volume tiers and packages, versioned over time
- Period close job that computes line items per customer and produces invoices as JSON and PDF
- Late-event handling with a configurable grace window and adjustment lines after invoices are finalised
- Customer-facing usage dashboard and an embeddable usage widget for the product using the engine
- Client SDK in one language with batching and retry, plus OpenAPI documentation
- Recompute tool that rebuilds any invoice from raw events and proves it matches
If you have time left
- Prepaid credit balances with alerts at thresholds
- Push finalised invoices to Stripe or Lemon Squeezy for payment collection
- Spend limits that return a signal to the product when a customer exceeds a budget
The problem API products have with usage-based billing
More products charge by usage: API calls, messages sent, minutes transcribed, tokens processed, gigabytes stored. For a small startup this sounds simple until they build it. Events arrive twice when clients retry. Some arrive after the month has closed. Pricing changes mid-month. A customer disputes an invoice and nobody can show which events produced it. Teams end up with a cron job, a SQL query and a spreadsheet, and billing bugs become customer trust problems.
What already exists and the gap
- Lago is an open source metering and usage-based billing platform that can be self-hosted.
- OpenMeter is an open source metering project, acquired by Kong in 2025 and being folded into Kong Konnect.
- Orb and Metronome are hosted usage billing platforms aimed at funded SaaS companies.
- Stripe Billing supports usage-based prices through its metering features.
Mature options exist, so this project is not about finding an empty market. It is about building a smaller, well-understood engine with provable correctness, and pairing it with the local reality many startups face: payment providers that are not available everywhere, so invoices must be generated independently of the processor. As a portfolio piece, few projects show backend depth as clearly.
What you build
Users: the product team integrating the engine (API keys, metric and plan setup), finance (reviews and finalises invoices), and the end customer (sees their usage dashboard).
Flow: the product sends events with a customer ID, event name, timestamp, properties and an idempotency key. The engine stores raw events, maintains running aggregates, applies the customer's plan at period end, and produces an invoice. Anything that happens later becomes an adjustment rather than a silent change.
The technically interesting part
Exactly-once effect over at-least-once delivery. Clients will retry. Deduplicate on idempotency key within a window, store raw events immutably, and make aggregation derivable from raw events. The same principle Stripe uses for idempotent API requests applies here to every usage event.
Aggregation that stays correct and fast. Keeping a running counter is fast but fragile; recomputing from raw events is correct but slow. Build both: incremental aggregates for dashboards, and a recompute path for invoices. Then prove they agree. Unique counts over large sets are a good place to discuss exact counting versus approximate sketches, and to measure the trade-off.
Time. Event time versus arrival time, customer time zones for period boundaries, plan versions that change mid-period, and late events after an invoice is final. Write these rules down as a specification, then test them.
How to evaluate it
- Correctness: a generator creates millions of events with 5 percent duplicates and 1 percent late arrivals. Invoices from the incremental path must equal a from-scratch recompute for every customer.
- Throughput: sustained ingestion rate and 95th percentile ingest latency on one modest machine, measured with k6. Report where it bottlenecks.
- Query speed: dashboard query latency for a customer with 10 million events, before and after pre-aggregation.
- Developer experience: 3 developers integrate the SDK into a sample app; time to first invoiced event and the friction they report.
Suggested plan
- Weeks 1 to 3: study Lago's and Stripe's public docs on metering, write your own specification of metrics, plans and time rules.
- Weeks 4 to 8: ingestion API, idempotency, raw event storage.
- Weeks 9 to 13: metric aggregation, incremental and recompute paths.
- Semester 2, weeks 1 to 5: pricing engine, plan versions, period close, invoices.
- Weeks 6 to 9: late events, adjustments, dashboards, SDK.
- Weeks 10 to 14: correctness and load evaluation, developer study, report.
Path to a product
The realistic first customer is a small API startup or an agency running AI features that bills clients by usage, which cannot yet justify a hosted billing platform. Release the engine as open source and sell a hosted version or support. Alternatively, run your own tiny API product on top of it and let the engine prove itself there.
Scope warning
Do not build payment processing, tax calculation, dunning or a general accounting system. Do not chase distributed streaming infrastructure such as Kafka unless your measurements show you need it. One database done right beats five services done halfway.
Learn what you need on Sefism
- System design roadmap : idempotency, aggregation and time handling at the core of this engine.
- Backend roadmap : API design, auth and data modelling.
- Stripe Documentation : study how metered prices, idempotency keys and invoices are modelled.
- OpenAPI Specification : document the ingestion API properly.
- Grafana k6 Documentation : build the throughput and latency tests.
- Fundamentals of Data Engineering : event time, late data and storage trade-offs.
Get help with this idea
Write the time and pricing specification before any code; it is the part evaluators will question. Tauseef can help you tighten the scope, choose a stack your team can finish with, and design an evaluation your examiners will respect. If you are new here, create a free account first.
Ideas and guidance, not finished projects
These are project ideas and scoping guidance, published free for students to use as a starting point. I do not build, write, or sell final-year projects, and I do not complete coursework for anyone. Take an idea, make it yours, and build it.
Not sure this one fits you?
I help students pick an idea that matches their skills and their deadline, then scope it down until it is finishable. Guidance only, never done for you.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
Follow along
New writing, resources and project ideas land here first.