Title: The service I am building is usage-based, i.e.<p><pre><code>  * I am charging per second the service was used, e.g. USD 0.01&#x2F;second
  * I would like to give credits upon sign-up.
  * There is no monthly minimum.
</code></pre>
At the moment, I am thinking that I can achieve this with just a few tables:<p><pre><code>  * `billing_account (id, billing_rate_id, running_balance)`
  * `billing_rate (id, rate)`
  * `account_credit (id, billing_account_id, timestamp, amount, function_execution_id)`
  * `account_debit (id, billing_account_id, timestamp, amount, source [platform_credit or stripe])`
</code></pre>
When a user creates an account, I would create an entry in `billing_account` and associate whatever the current `billing_rate`. I would also create an `account_debit` entry with `source=platform_credit` and update `billing_account` `running_balance` value to reflect their balance after the `platform_credit`.<p>Then whenever they run a function that costs them, I create `account_credit` account with an entry equal to the amount they spent and update `billing_account` `running_balance` value.<p>When they top-up their account, I would just add entry to `account_debit` and update the balance again.<p>This appears to cover all my use cases, but I wanted to check with anyone who&#x27;s designed such database schemas before.
Upvote: