A metered license bills for what the customer uses — API calls, render jobs, processed documents. That model has a sharp edge the per-seat and per-feature models don't: the thing you are counting keeps happening whether or not the client can reach your license server. A thirty-second network blip during a batch of ten thousand API calls is not a reason to stop serving the customer, and it is certainly not a reason to forget those calls happened. Yet a naive meter that phones home on every event does exactly one of those two things during an outage.
The real question
So the question is not "how do I count usage" — it is "how do I keep counting while disconnected, and reconcile honestly when the connection comes back, without losing events, double-counting retries, or letting a client quietly rewrite its own bill." That is a distributed-systems problem wearing a licensing hat, and it has a specific, well-understood shape: a local append-only ledger, a signed batched report, and an idempotent server-side merge.
This is a different mechanism from the two it is often confused with. Online quota enforcement blocks a draw in real time when the balance hits zero — it needs the network on every call and is not what you reach for during an outage. Grace-window validation keeps a license valid through a transient outage so the app does not lock the user out; it answers "is this license still good?", not "how much did it consume?". Reconciling metered usage is the third thing: counting that survives the outage and settles up afterward.
The local ledger
Start at the client. Every billable event appends one immutable entry to a local ledger. The entry is never updated and never deleted — append-only is what makes it tamper-evident, because rewriting history leaves a hole.
// One immutable local ledger entry, written at the choke point every time // usage is consumed — online or offline. Never updated, never deleted. public sealed record UsageEntry( string ReportId, // stable id for this unit of work, e.g. the job/request id long Seq, // monotonic per-client counter; a gap means a dropped ledger string Pool, // which meter this draws from, e.g. "api-calls" long Amount, // units consumed DateTimeOffset RecordedAt); // client clock — advisory only, never trusted for ordering Two fields carry the weight. ReportId is generated by the client and is stable for the unit of work, not the upload — the same API request always produces the same report ID, so a replay is recognisable. Seq is a monotonic counter that increments by exactly one per entry; it is the tamper evidence, because a ledger that was rewound or had rows deleted can no longer present an unbroken run of sequence numbers.
The SDK records against the ledger with no server round-trip, so a billable call is served at local speed whether or not the network is up:
var client = KeyrightClient.Initialize(options); // At the one point where a billable call is served. Appends locally and returns; // no network dependency on the hot path. RecordResult rec = await client.RecordUsageAsync(new UsageDraw( pool: "api-calls", amount: 1, reportId: request.Id)); // stable id: the same request always carries the same id if (!rec.WithinOfflineCap) { // We have hit the conservative *offline* sub-cap — stop ourselves before the // real plan cap, because we cannot see the authoritative total while offline. return TooManyRequests("Usage paused pending reconnect."); } ServeApiCall(request); // only runs once the event is durably in the ledger RecordUsageAsync appends to the ledger and checks the local offline sub-cap — deliberately lower than the plan cap, because while disconnected the client is counting blind and should leave headroom for whatever other nodes are also consuming.
The signed report
When connectivity returns, the client does not replay events one by one — it uploads everything since the last acknowledged sequence as a single signed report. Batching is not just an optimisation; the envelope's seq_from/seq_to range is what lets the server prove the run is contiguous.
{ "license_id": "lic_7Q2f8K", "client_id": "node-3f9c", "seq_from": 4120, "seq_to": 4123, "records": [ { "report_id": "job-9af2", "seq": 4120, "pool": "api-calls", "amount": 1, "recorded_at": "2026-11-30T02:14:05Z" }, { "report_id": "job-9af3", "seq": 4121, "pool": "api-calls", "amount": 1, "recorded_at": "2026-11-30T02:14:06Z" }, { "report_id": "job-9af4", "seq": 4122, "pool": "api-calls", "amount": 1, "recorded_at": "2026-11-30T02:14:08Z" }, { "report_id": "job-9af5", "seq": 4123, "pool": "api-calls", "amount": 1, "recorded_at": "2026-11-30T02:14:11Z" } ], "sig": "ed25519:9c3f…" } The signature covers the whole envelope, so a client cannot shave a few records off a batch to under-report without the signature failing. The server verifies the signature first, rejects the entire report if it fails, and only then looks at the contents.
The idempotent merge
The server's job is to fold this batch into the authoritative total exactly once, no matter how many times the same batch arrives. The report ID is the primary key, and the insert is a no-op on conflict:
-- Idempotent insert: a report_id the server already holds is silently ignored. -- A retried or overlapping batch therefore merges to the union, never the sum. INSERT INTO usage_records (report_id, license_id, pool, amount, client_seq, received_at) VALUES (@report_id, @license_id, @pool, @amount, @client_seq, now()) ON CONFLICT (report_id) DO NOTHING; That one ON CONFLICT clause is the whole idempotency story. A client that uploads a batch, never sees the acknowledgement, and retries the identical batch inserts nothing the second time. Two batches that overlap — because a flaky link made the client re-send a window it had already delivered — merge to their union. Out-of-order arrival is a non-event: records are keyed by their own report ID and ordered later by the server's own received_at plus the client sequence, never by the order batches happened to land.
Before trusting the batch at all, the server checks the sequence run against the highest sequence it has accepted for this client:
-- Reject tampered or truncated ledgers: the batch must continue the run with no -- backwards motion and no gap. A hole or a rewind means the ledger was rewritten. SELECT last_seq FROM client_cursors WHERE client_id = @client_id FOR UPDATE; -- reject if @seq_from <> last_seq + 1 (gap or replay-with-rewind) -- reject if @seq_to < @seq_from (non-monotonic) -- on success: UPDATE client_cursors SET last_seq = @seq_to WHERE client_id = @client_id; Applying the cap after the merge
Here is the step that separates honest reconciliation from silent revenue loss: the plan cap is enforced after the merge, by summing what the server now holds — not by trusting a per-batch running total the client sent.
-- Sum everything the server holds for this period, then compare to the cap. SELECT COALESCE(SUM(amount), 0) AS used FROM usage_records WHERE license_id = @license_id AND pool = 'api-calls' AND received_at >= @period_start AND received_at < @period_end; If used exceeds the plan cap, the overshoot is now visible — it was not dropped on the floor the way a client that simply stopped counting would have dropped it. What you do about it is policy, surfaced on the client's next online check:
ReconcileResult r = await client.ReconcileAsync(); if (r.OverCap) { // We only learn of the overshoot now, at reconcile. Choose the posture up front: // grace band → keep serving, bill the overage, nudge to upgrade // hard stop → block the next draw until the customer tops up ApplyOveragePolicy(r.Pool, used: r.Used, cap: r.Cap); } Caveats — where this breaks
Three limits are inherent, and pretending otherwise is how metered systems lose money or lock out paying customers.
Offline over-consumption is unavoidable. While a client is offline the server cannot block a draw that crosses the cap, because it cannot see the draw. You can only detect the overshoot at reconcile — which is exactly what applying the cap after the merge buys you. The mitigation is the conservative offline sub-cap in RecordUsageAsync: the client stops itself well below the plan limit, leaving headroom for other nodes, so a single disconnected node can't blow the whole plan.
A client that never reconnects never reports. An append-only ledger on a machine that stays dark forever is revenue you will never see, and worse, a loophole: stay offline, serve unlimited usage. The pairing is a maximum offline window — a signed validity horizon after which the client fails closed and refuses to serve until it has reconciled at least once. Counting offline is a bounded trust extension, not an open tab.
The client clock is untrusted. recorded_at is in the envelope for diagnostics and display, never for ordering or period assignment — a client whose clock is wrong (or deliberately set back) must not be able to shove usage into a cheaper period. The server orders and buckets by its own received_at plus the monotonic client sequence. The client's wall clock is a hint, not evidence.
Doing this with Keyright
Keyright carries metered pools as a first-class part of the license, so offline accumulation and reconciliation are part of the SDK rather than a billing pipeline you build on the side. RecordUsageAsync appends to the signed local ledger and enforces the offline sub-cap on the hot path; ReconcileAsync uploads the signed batch on reconnect; and the issuing service does the idempotent merge, the sequence check and the post-merge cap. The same license already handles your seats, entitlements and multi-pool metering, so a disconnected meter is a property of the license, not a second system. The Community Edition is free and self-hosted, so you can wire a metered client end to end — ledger, batch, merge and all — before you commit; see the Keyright docs for the exact metering surface.
Takeaway: A metered client that stops counting during an outage is a bug, not a safety feature. Keep an append-only, sequence-stamped local ledger, upload it as a signed batch on reconnect, dedup on a stable report ID so retries and overlaps merge instead of summing, and apply the cap after the merge so the overshoot is detected rather than dropped. You cannot make offline over-consumption impossible — but you can make it bounded, visible, and honestly reconciled.

