openmeter icon indicating copy to clipboard operation
openmeter copied to clipboard

Time-based quotas + webhook events when quota is reached

Open binaryfire opened this issue 1 year ago • 3 comments

Preflight Checklist

  • [X] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Problem Description

A lot of projects use quota-based billing instead of usage-based billing (eg. pay $X for Y credits/month). Currently the only way to implement this with OpenMeter is to make a GET request after every event to check the meter total. That's not very scalable.

Proposed Solution

This is how I imagine it would work:

  1. Each meter can have optional associated quotas with timeframes of Daily/Weekly/Monthly/Yearly/No timeframe. The timeframe determines when a quota resets.
  2. A webhook event is triggered when a quota is reached within the given timeframe. This can be used to inform another application that a quota has been reached.
  3. Allowing multiple quotas to be associated with each meter would let us trigger webhooks events for things warnings too.

Smaller and indie projects often prefer quotas because of the simpler billing model. I think adding this functionality would open up OpenMeter to a lot more developers.

PS. Another option could be returning the current meter's usage in the HTTP response when every event is posted. But I'm assuming that would require a database lookup on every event, which could get expensive.

Alternatives Considered

A simple Redis-based counter that is checked before each outgoing request is made.

Additional Information

No response

binaryfire avatar Jul 05 '23 07:07 binaryfire