A user starts a live camera session, runs it for half a minute, and closes the tab. When they come back, the balance can still show the credits set aside at the start. The browser is gone, but the server still has a session to close and an amount to reconcile.
I encountered this while building LiveFaceSwap, a browser studio that meters live video by the second. A camera preview can stop before the billing record catches up. I wanted the server to settle from the usage recorded for that session and return the rest of the reservation.
Set a ceiling before opening the stream
At the start, the server reserves up to the amount the user can spend on a single session. It writes the ledger debit and the new session together, with a balance check on the debit. The reservation also sets the budget for the live connection. LiveFaceSwap currently meters at 0.6 credits per second, with a 900-second session cap.
Here is an example. With 60 credits reserved, the budget covers 100 seconds.…