USG-4Recommended
Accept late events up to a fixed cut-off
Bill each event by the time it happened. Accept late events for a fixed grace window, such as 24 hours after the period ends, then close the period.
How to do it
Queues, retries and offline clients deliver events after the period they belong to. Use the time the work happened, not the time the event arrived. Wait for the grace window before you send the period's usage to the billing provider. Put an event that arrives after the close in the next period, with a note on its line, or drop it by a written rule. Never reopen a sent invoice. Providers set their own limits on old timestamps, such as 35 days, so keep your window shorter. Order rules for late messages are in Don't rely on event order.
How to check
A test with a fixed clock sends an event that happened on the last day of the period and arrives 2 hours after it ends. It counts in that period. One that arrives 2 days later lands in the next period, and the closed invoice does not change.
Sources
Related rules
- API-54 Don't rely on event order in API design
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/usage-billing/metering/late-usage-cutoff">Agent Wranglers usage-based billing playbook</a>. In code you write, add a comment next to it with the same link.