Events and metering
Driptab's usage-based billing is driven by events. Your backend sends an event every time a billable action occurs. At period close, those events are aggregated into invoice line items.
What is an event?
An event is a single billable occurrence: an email sent, a gigabyte stored, an API call made. Events have:
| Field | Description |
|---|---|
transaction_id |
Your stable, unique ID for this event. Must be unique per subscription per organization. |
subscription_id |
Which subscription to attribute the usage to (or external_id prefixed with ext:). |
code |
Which billable metric this event contributes to (e.g. mail_out). |
value |
Numeric value as a string (e.g. "1", "24576"). Used by sum, max, latest aggregations. |
properties |
Optional JSON object with additional context. |
timestamp |
When the event occurred (ISO-8601 UTC). |
Sending an event
dtab ev ingest \
--transaction-id msg_01HX4K2MNPQRSTUVWXYZ000001 \
--subscription ext:your-sub-id \
--code mail_out \
--prop count=1
POST /v1/events
Authorization: Bearer dtab_…
X-Project-Id: <project_id>
{
"transaction_id": "msg_01HX4K2MNPQRSTUVWXYZ000001",
"subscription_id": "ext:your-sub-id",
"code": "mail_out",
"value": "1",
"timestamp": "2026-06-08T14:23:00Z"
}
Response:
{ "accepted": true, "duplicate": false }
If the same transaction_id is sent again:
{ "accepted": true, "duplicate": true }
The event is acknowledged but not counted again. Your backend can retry event ingestion safely.
Idempotency
Idempotency for events is enforced at two levels:
-
The meter — each subscription's meter keeps the
transaction_ids it has seen in the current period. Concurrent or retried events for the same subscription are applied one at a time; a duplicate is never double-counted. -
The event store — an event's stream is keyed by
(organization_id, transaction_id), so a second append of the same event is refused even on a path that bypasses the meter.
The seen set is reset when the period closes, so it does not grow without bound.
transaction_id uniqueness is per-period per-subscription.
How aggregation works
Each billable metric has an aggregation_type that determines how raw event values
roll up into the period total:
| Aggregation | How it works | Example use |
|---|---|---|
sum |
Add all value values in the period |
Email volume, bytes stored |
count |
Count the number of events | API calls (ignoring value) |
count_unique |
Count distinct values of field_name |
Unique active users |
max |
Peak value in the period |
High-water-mark storage billing |
latest |
Most recent value in the period |
Current seat count |
Aggregation does not happen at query time. The subscription's meter keeps a running counter per metric for the current period and updates it on each accepted event.
How metering works
Each active subscription has one meter, keyed {organization_id}:{subscription_id}.
Its events are applied in order, one at a time, and its counters are folded from an
append-only event store, so:
- Concurrent events are exact: fire thousands at the same subscription and the final counter is exactly right, with no locking on your side.
- Nothing is lost on restart: a counter is a fold over stored events, so it is rebuilt rather than recovered.
Raw event storage
Every accepted event is kept in the event store for:
- Audit: who sent what, when, with what properties.
- Recompute: counters can be replayed from the raw events at any time.
- Analytics: query patterns like "top 10 customers by mail_out this month".
The event store is append-only.
Period close
At current_period_end:
- Final per-metric counters are read from the meter.
- Fees are computed for each charge:
standardcharges:units × properties.amount, rounded to cents once.flat_feecharges: the catalog item's price (or override).
- The invoice and its fees are written in one atomic step.
- Counters and the dedup set are reset.
current_period_start/endadvances by one interval.- The next period close is scheduled.
- An
invoice.createdwebhook fires.
Late events
An event whose timestamp falls before current_period_start arrives after the
relevant period has already closed. Driptab's MVP behavior is to reject late events
with an error. Do not silently roll them into the current period — that would
misrepresent when the usage occurred. An explicit adjustment workflow will be added
in a future release.