Metering & Billing Integrity — Agora Video Streaming

Overview
Agora overtook AWS as our single largest infrastructure line item, and we couldn't attribute the spend to a customer or verify the invoice — so we decided to rebuild metering from the vendor's own event stream instead of trusting a browser timer.
The problem
Agora, the WebRTC provider carrying every live drone video feed, had become our biggest infrastructure cost, ahead of AWS, but nobody could answer two basic questions: which customers were actually driving that spend, and was the vendor's invoice even correct. The existing meter was a browser-side timer that only pinged from one dashboard, kept "counting" only as long as a tab stayed open even though the underlying video channel could keep running and billing after it closed, and never measured audio at all, despite drone feeds being video-only by design — audio alone still made up close to half of total spend. There was no way to bill fairly and no way to catch overspend.
What I built
A server-authoritative metering pipeline that treats Agora's own webhook events, not our client, as the source of truth. Every stream carries a per-join, per-surface token; a session-ingest service turns the resulting webhook lifecycle into idempotent, reorder-safe sessions, with a scheduled job capping anything left stuck open so a stale connection can't inflate minutes forever. A single device can generate three independent charges at once, the drone's own publish, viewer audience minutes, and any video pushed to an external monitoring system, so each is classified and billed separately with no double-counting. The billing math never uses a hardcoded rate: a per-minute factor is derived by dividing the actual invoice dollars by the minutes we metered, so every customer charge reconciles back to the vendor invoice by construction instead of by hope.
Impact
Recovered roughly $30k/month of previously unaccounted usage revenue, moved reconciliation from "trust the invoice" to a system that ties out to it by construction, and gave the business its first real visibility into where the spend was actually going, including that close to half of it was audio nobody was consuming.








