How PAYG metering and billing works
This page is for platform operators who run pay-as-you-go (PAYG) billing on a Kube-DC installation. It explains the whole path: how usage is sampled, how each UTC hour is proven, how hours are priced, and how a monthly statement becomes a paid invoice. It also lists every workload that takes part.
To turn PAYG on, read PAYG billing (optional). To select sources and run the first statement, read the billable PAYG profile.
Design rules
These rules hold for every product and every source:
- Evidence, not configuration, creates a charge. A price on the rate card does not bill anything by itself. Each charged quantity points to retained usage rows and the evidence behind them.
- The hour is the unit of proof. PAYG proves usage one UTC hour at a time, during the month, while the evidence is fresh. Month-end processing reuses those hours instead of re-reading the whole month.
- Unknown is never zero. A missed sample is a recorded gap, not zero usage. A gap makes the affected meter-hour free. It never becomes a guessed quantity.
- Errors are not gaps. Contradictory ownership, corrupt evidence, an unpriced product or an invalid source authority stop the statement. They are never turned into free hours or zero usage.
- Nothing is rewritten. Usage rows, rate-card revisions, sealed decisions, finalized statements and approvals are immutable. A correction is a new, typed record.
- Billing stays outside the write path. Customer workloads, log writes and metric writes never call or wait for PAYG, its database or the payment provider. If billing stops, tenants keep running and the affected hours are free.
Components
All PAYG workloads run in the monitoring namespace. They are deployed by the
optional platform/payg Fleet bundle and the source bundles that an
installation selects.
| Component | Kind | Responsibility |
|---|---|---|
kube-dc-metering | Deployment, one replica | Minute collector, producer API, billing API, journal rollups, budget evaluation and the Stripe exporter. |
kube-dc-settlement-worker | Deployment, one replica | Runs /payg-statement schedule: opens monthly periods, prepares closed hours, and seals, closes and finalizes due periods. |
| Storage captures | CronJobs | Capture Ceph RBD images and RGW buckets every five minutes. |
| Fee censuses | CronJobs | Capture managed-service and Kubernetes fee records every five minutes. |
| Stock telemetry | CronJobs | Read Loki and Mimir usage for the previous hour, once per hour. |
| Hour proofs and payable projector | CronJobs | Prove each closed source hour and project it into usage rows. |
| Evidence upkeep | CronJobs | Move finished evidence to the archive and expire unreferenced raw data. |
| Metering database | PostgreSQL database | Usage journal, evidence, proofs, decisions, statements and approvals. |
| Backend and consoles | Kube-DC chart | Tenant estimates, invoices and payment method; admin rate cards, policies and settlement periods. |
The jobs reference lists each CronJob with its schedule.
The metering database uses its own role and verified TLS. By default it shares the installation's PostgreSQL cluster. A large installation can select a dedicated cluster. Each workload uses its own small connection pool.
What is measured
Each priced product on the rate card names one meter. The meter decides which source measures it and how. The following table shows the products of a typical card.
| Product family | Example SKUs | Measured from | Measurement |
|---|---|---|---|
| Compute | compute.standard.cpu, compute.standard.memory | Minute collector | Kubelet-admitted effective requests of running Pods, including the Pods that run virtual machines. Pod overhead is not charged. |
| Public IPv4 | network.ipv4 | Minute collector | Each public address held by an EIp, from allocation until release. |
| Local-path disks | storage.block.local_path | Minute collector | Provisioned capacity of local-path volumes. |
| Ceph block storage | storage.block.ceph_rbd | RBD capture | Provisioned size of each RBD image, at five-minute boundaries. |
| Object storage | storage.object.current | RGW capture | All stored bytes of a bucket, at five-minute boundaries. |
| Backups | storage.backup.base, .incremental, .wal, .replica | RGW capture and archive registrations | Bytes in registered backup archive roots, at five-minute boundaries. |
| Managed-service fees | service.<family>.<tier>.management | Fee census | Service-seconds of one logical managed service. |
| Managed Kubernetes fees | service.kubernetes.standard.management, service.kubernetes.ha.management | Fee census | Service-seconds of one managed control plane. |
| Metrics | metrics.active_series | Stock telemetry | Active series per tenant on a five-minute grid. |
| Logs | logs.compressed_writes | Stock telemetry | Bytes of successfully stored, compressed log chunks. |
A product without a qualified source stays disabled on the card. It is listed but cannot create charges. Prices are quoted per hour, per GiB, or per 730 hours, which is a quote basis for one month. Calendar months can be longer or shorter; the exact quantity is always charged.
Minute collection
The minute collector in kube-dc-metering measures compute, public IPv4 and
local-path disks.
Every minute, the collector does the following:
- Lists Organizations, Projects, Namespaces and the priced resources from the Kubernetes API.
- Reads resource requests and Pod phase from kube-state-metrics through Prometheus. A query result older than 90 seconds counts as missing.
- Evaluates one minute for every participating organization, in memory.
- Extends or closes hour segments. A segment is a run of identical minutes of one component: one resource, meter, owner, price revision and quantity. A segment never crosses a UTC hour boundary. A change, a missed minute, or the end of the hour closes it.
Every five minutes, at each hour boundary and on shutdown, the collector runs one tick transaction per organization. The transaction checks the writer fence, inserts the closed segments into the usage journal, replaces the organization's checkpoint of open segments, and writes the coverage of completed hours.
Coverage is a 60-bit map of observed minutes per organization, meter family and hour. When an hour is fully covered, the collector writes an hourly collector receipt. Settlement reads these receipts instead of the individual segments.
The collector has one writer. It holds a database lock for its lifetime, and a stale writer cannot insert anything. After a restart, the collector resumes from its checkpoints. The minute of the restart has no previous sample, so it is a recorded gap.
By default, only organizations on a PAYG policy are collected.
Five-minute source evidence
Ceph storage and managed-service fees are proven from five-minute captures. Stock telemetry uses the same five-minute grid.
A capture CronJob runs at every five-minute boundary and retains the exact capture. After the hour closes, two workers build on those captures:
- The hour proof worker,
kube-dc-selected-hour-proofs, revalidates each physical source for the latest closed hours. It writes one proof per source and hour. - The payable projector,
kube-dc-s3-payable-evidencerunning thecollect-live-native-hoursaction, projects proven hours into usage rows. Despite its historical name, it covers RBD, object storage, backups and both fee families.
Both workers wait four minutes after the hour ends, then process the latest two closed hours. They never accept explicit date ranges, so they need no monthly reconfiguration. The projector attempts at most one expensive hour per physical store in each pass. Hours that are already projected are skipped, so a retry is safe and an older hour catches up on the next pass.
An hour is proven only when all thirteen boundaries are present and every quantity has a reconciled payer. A missing, late or conflicting sample leaves the hour incomplete.
Ceph block storage
kube-dc-rbd-census reads the Ceph pools and RBD images every five minutes,
together with the PersistentVolumes, PersistentVolumeClaims, Namespaces,
Projects and Organizations that own them. It runs its Ceph commands only in
the dedicated kube-dc-payg-ceph-tools StatefulSet. It verifies the identity
of that pod before and after each read.
When a new customer image appears, the capture adopts it. Adoption checks the CSI reservation, the volume and claim UIDs, the Namespace, Project and Organization chain, and the StorageClass. It then records a payer binding and a class binding. These bindings outlive the claim, so a retained volume stays attributed to its payer.
An image without a payer is an unattributed gap. That image is charged to nobody, and the rest of the hour is billed. For every hour, the observed capacity equals paid plus platform plus pending plus unattributed capacity.
Object storage and backups
kube-dc-rgw-census reads the population of every RGW bucket at each
boundary, using the same toolbox pattern. The S3 inventory producer,
kube-dc-s3-producer, independently records which ObjectBucketClaim,
Project or Organization owns each bucket. The collector also records its own
witnesses of claims and object-store users.
Backups are a subset of object storage. The managed-services hub registers each backup archive namespace with the billing API. At each boundary, the bytes under a registered archive root move from generic object storage to the matching backup SKU. Customer and platform shares must add up to the observed total. A registration is permanent, so a backup keeps its payer after the service is deleted.
kube-dc-s3-hourly-audit runs at minute five of each hour. It certifies the
previous sampled hour and writes a non-billable preview. The payable projector
writes the charged quantities.
Managed-service and Kubernetes fees
A managed service carries one fixed management fee, prorated by service-time. Replicas, Pod sizes and storage do not multiply it. The service's dedicated CPU, memory and storage are charged separately as ordinary resources.
The Services hub and runner, and the Kubernetes control-plane manager, write signed, immutable lifecycle records for each service. Fee census CronJobs capture those records every five minutes. A fee hour needs all thirteen captures, a baseline from before the hour, and a fee enrollment that was activated before the hour started. The enrollment pins the writers it trusts. When a release replaces the writers, the writer-renewal CronJob activates a successor at the next whole hour, and the hours in between are free.
For setup, read managed-service fees.
Stock telemetry
Logs and metrics are measured from stock, unmodified Loki and Mimir. Nothing in the log or metric write path calls billing.
At minute five of each hour, kube-dc-stock-mimir-shadow and
kube-dc-stock-loki-shadow read the previous hour from Prometheus on the
same 13-point, five-minute grid:
- Metrics:
cortex_ingester_active_series, per tenant. The quantity is series-seconds, divided by the replication factor. - Logs: the increase of
loki_ingester_chunk_stored_bytes_total, per tenant. Successful recovery rewrites count as writes.
The workers also check scrape freshness, up, process restarts, ring
membership, build information and, for Mimir, the replication factor. A
restart, a ring change or a missing point makes the hour unknown for that
backend.
Only tenants named namespace-<Namespace UID> select a customer. The
Namespace UID is matched to its organization and Project for the whole hour.
Platform tenants and Namespace names never select a payer. Each run writes
unpriced hourly receipts and, for organizations on a PAYG policy, the payable
projection.
Producers and the usage journal
The usage journal is the single, append-only record of priced usage. It is partitioned by month. The minute collector writes segments into it directly. Every other source writes as a registered producer.
- Declaration. The installation declares its trusted producers in
PAYG_DECLARED_PRODUCERS. Each entry binds a producer ID to one identity, its meters and its scope. Changing a declaration opens a new epoch. - Delivery. An external producer posts numbered batches with its Kubernetes ServiceAccount token. The receiver checks the token, the identity, the scope, the open epoch and the sequence in one transaction. It acknowledges only after commit. A skipped sequence is recorded as a hole.
- Internal projectors. RBD, object storage, backup, fee and telemetry projections write under reserved internal identities. These meters cannot be delivered through the producer API.
- Refusals. A refused batch stays in the producer's spool. Evidence that ages out of the spool is reported as a gap before it is dropped.
Attribution
Each usage row belongs to one organization and, where it applies, one Project. The collector records ownership intervals as it observes Namespaces, Projects and Organizations. Sources resolve their payer from those intervals and from their own retained bindings, never from names alone.
Missing ownership is a gap. Two contradictory owners for the same hour are an error that blocks the statement.
The meter-hour rule
Usage is charged in decisions of one organization, one meter and one UTC hour, across all Projects, resources and sources.
| Outcome | When | Effect |
|---|---|---|
| Paid | Every required source for the meter-hour is complete and reconciled. | The hour is rated at the exact rate-card price. |
| Free | A typed measurement gap exists. | The whole meter-hour is free, including any observed part. The statement lists it with its reason. |
| Blocked | Contradictory or corrupt evidence, an unpriced product, an invalid source authority, or a database or transport failure. | The period cannot finalize until an operator resolves the error. |
Free meter-hours are enabled per settlement policy, as the free-meter-hours.v1
rule. Decisions are sealed once, after the period's completeness cutoff.
Evidence that arrives later cannot turn a free hour into a charge or a positive
correction.
Rate cards and money
A rate card has immutable, published revisions. Each organization's billing policy names one revision. Changing a price means publishing a new revision and moving organizations to it at a future boundary.
- Pricing context. A minute is priced by the policy and card revision in force at its start. A change effective at 10:17:30 applies from the minute that starts at 10:18. A segment never spans two revisions, and retroactive changes are refused.
- Units. Each rate has a price unit and a conversion from the meter's base unit. For example, CPU is metered in vCPU-seconds and priced per vCPU-hour, which is 3,600 vCPU-seconds.
- Precision. Rating uses exact rational arithmetic. Each figure on a line is rounded once, half-up, to 12 decimal places.
- Cents. The statement total stays exact until export. The exporter rounds the net total once to the currency's minor unit, half away from zero, then spreads the cents across lines by largest remainder, so the lines add up exactly. The JSON and CSV files use the same rule.
- Credits. Amounts are never negative. A credit is a typed correction.
Monthly settlement
A settlement period covers one organization for one UTC calendar month. The
settlement worker, kube-dc-settlement-worker, runs every minute, and runs
back to back while it makes progress.
Each pass has these phases, each with its own time budget:
- Opening. Opens the current month's period for every account the standing policy covers, and catches up the previous month after a missed pass.
- Due. Seals, closes and finalizes periods whose cutoff has passed.
- Source continuation. In the last seven days of the month, continues the configured source enrollments into the next month.
- Preparation. For each open period, prepares the latest closed hour and one older slice. It verifies telemetry, writes collector receipts and prepares the shared source proofs. Preparation never rates or seals.
Completeness cutoff
The cutoff is the end of the month plus PAYG_SETTLEMENT_CUTOFF. The bundle's
default is 1h, and the qualified paid profile uses 2h. Evidence that
arrives before the cutoff counts. An operator can extend the cutoff of an
open period with an append-only extension that keeps the original deadline on
record.
Automation policy
PAYG_SETTLEMENT_AUTOMATION is the standing authorization for automatic
settlement. It is a JSON object:
{
"version": "settlement-automation.v1",
"scope": "billable-accounts",
"effectiveFrom": "2026-01-01T00:00:00Z",
"freeMeterHours": true,
"finalize": true,
"continueSources": true,
"earliestMonth": "2026-01"
}
freeMeterHours applies the meter-hour rule. finalize lets the worker
freeze statements. continueSources lets it carry source enrollments into the
next month. Approval is a separate act, described in
Statements, approval and invoices.
What happens after the cutoff
Because hours are prepared during the month, the work after the cutoff is bounded:
- The worker classifies the month in two-hour slices. Each slice commits on its own, so a restart resumes where it stopped.
- It re-checks free decisions and paid hours whose evidence changed since preparation.
- It seals the plan and writes every paid or free decision in one statement.
- Close rates the paid hours against the sealed plan. Rated lines keep pointers to their journal rows. Clean hours reuse the hourly rollups; only changed or partial hours read the raw journal.
- Finalize rechecks the evidence pointers and freezes the total. The period then has an immutable statement key.
A period whose meters all come from the minute collector seals directly from the hourly collector receipts.
Period states
| State | Meaning |
|---|---|
open | The month is collecting and preparing. |
closing | Rating found gaps or unpriced components to resolve. |
validated | Rated with no open gaps or unpriced components. |
finalized | Frozen. Only export, acknowledgement or failure can follow. |
exported | An invoice or export was created for the approved statement. |
acknowledged | The payment provider confirmed the invoice. |
failed | The period could not complete and needs an operator. |
Statements, approval and invoices
A finalized statement contains its lines (SKU, meter, quantity, unit price, amount, rate and policy revisions), Project and service attribution, adjustments, free meter-hours with their reasons, and a money block with the minor-unit total.
Approval
Approval names the exact statement key, so a changed statement cannot be approved by mistake. An immutable snapshot of the statement is saved with the approval. The snapshot stays available after the raw evidence is archived.
There are two approval paths:
- Finance approval. A platform administrator reviews and approves the statement under Settlement periods in the admin console.
- Automatic issuance. With the optional
automatic-stripe-issuancecomponent, the exporter approves a statement automatically when the payer is enrolled for recurring billing, the period starts at or afterPAYG_EXPORT_AUTO_ISSUE_FROM, the worker finalized the period after its cutoff, and the period has no corrections.
Export
An approved statement leaves Kube-DC in one of two ways:
- JSON or CSV file. Download it from the admin console or with
/payg-statement approved-export. Import it into an existing billing system and deduplicate on the statement key. A download does not record delivery. - Stripe invoice. With
PAYG_EXPORT_PROVIDER=stripe, the exporter inkube-dc-meteringruns every ten minutes. It records its intent, looks for an existing invoice with the same statement key, and otherwise creates one invoice item per line, checks the total, and finalizes the invoice. Its idempotency key and a per-period lock prevent duplicates.
PAYG_EXPORT_ORGANIZATION_UIDS and PAYG_EXPORT_APPROVED_AFTER limit which
approvals can create invoices. PAYG_EXPORT_CREATION_PAUSED=T stops new
invoices while existing ones keep reconciling.
Reconciliation and payment
The exporter re-reads every exported invoice from Stripe. Signed Stripe webhooks reach the backend and are forwarded to the billing API as a faster path. The billing API always re-reads the invoice and applies each event once.
- When the invoice is open, the period becomes
acknowledged. - When the invoice is paid, the payment state updates.
- When an invoice becomes uncollectible, a payment hold stops the organization from growing. Running workloads continue. The hold is released when no invoice of the organization is open or uncollectible.
Tenants see issued invoices, their payment status and the payment method under Manage organization > Billing & quotas.
Evidence retention
Every charged quantity can be traced from its rated line to journal rows, sealed decisions, source proofs and retained originals.
- Hot evidence stays in PostgreSQL while a period can still change.
- Archive. With the optional
hot-archivecomponent,kube-dc-payg-hot-maintenancemoves the bodies of financially finished evidence to two encrypted copies in object storage. A scope must be at least 30 days old, financially complete, verified in both copies and free of holds. Copies use object lock and server-side KMS encryption, and are kept for at least seven years. - Raw data expiry.
kube-dc-payg-shared-gcexpires raw capture data after seven days unless a proof, projection or decision still references it.
A missing or corrupt copy is reported as unavailable. It never becomes free usage or zero.
Tenant and admin views
| Audience | View | Source |
|---|---|---|
| Tenant | Month-to-date estimate in Project > Quota | Hourly journal rollups, priced at current list prices. A day still rebuilding shows as unknown, not zero. |
| Tenant | Budget and month-end forecast | Advisory. Budgets are evaluated every 15 minutes and send no email. |
| Tenant | Billing periods, invoices and payment method | Settlement periods and Stripe. |
| Administrator | PAYG prices | Published rate-card revisions. |
| Administrator | Organization billing tab | Billing policy, holds and spending. |
| Administrator | Settlement periods | Period state, statement review, approval and file download. |
An estimate is not an invoice. It can be incomplete until the period is sealed.
Jobs reference
All jobs run in monitoring. Schedules are the bundle defaults in UTC. An
installation runs only the bundles and components it selects.
| Workload | Default schedule | Bundle or component | Purpose |
|---|---|---|---|
kube-dc-metering | Continuous, one-minute loop | platform/payg | Minute collector, producer and billing APIs, rollups, budgets, Stripe export. |
kube-dc-settlement-worker | Continuous, one-minute passes | settlement-worker | Open, prepare, seal, close and finalize periods. |
kube-dc-rbd-census | */5 * * * * | platform/payg-rbd | Capture RBD images and adopt new customer images. |
kube-dc-rgw-census | */5 * * * * | platform/payg-rgw | Capture RGW bucket populations and archive members. |
kube-dc-s3-producer | Continuous, five-minute aligned | Per installation | Record bucket ownership. |
kube-dc-s3-hourly-audit | 5 * * * * | platform/payg | Certify the previous sampled S3 hour. |
kube-dc-managed-fee-census | */5 * * * * | platform/payg-managed-fee | Capture managed-service fee records. |
kube-dc-managed-fee-writer-renewal | 2-59/5 * * * * | platform/payg-managed-fee | Follow Services releases with a successor enrollment. |
kube-dc-kdc-fee-census | */5 * * * * | platform/payg-kubernetes-fee | Capture managed Kubernetes fee records. |
kube-dc-kdc-fee-writer-renewal | 2-59/5 * * * * | platform/payg-kubernetes-fee | Follow control-plane manager releases. |
kube-dc-stock-mimir-shadow | 5 * * * * | stock-telemetry-shadow | Measure the previous hour's active series. |
kube-dc-stock-loki-shadow | 5 * * * * | stock-telemetry-shadow | Measure the previous hour's compressed log writes. |
kube-dc-selected-hour-proofs | 2-57/5 * * * * | selected-hour-proofs, continuous-source-hours | Prove the latest closed source hours. |
kube-dc-s3-payable-evidence | 3-58/5 * * * * | continuous-native-hours | Project proven RBD, object, backup and fee hours. |
kube-dc-backup-census, kube-dc-archive-census, kube-dc-native-backup-census | */5 * * * * | platform/payg-backup | Diagnostic backup custody. Creates no charges. |
kube-dc-native-backup-hourly-audit | 5 * * * * | platform/payg-backup | Check backup boundary coverage. Creates no charges. |
kube-dc-payg-hot-maintenance | */5 * * * * | hot-archive | Archive finished evidence. |
kube-dc-payg-shared-gc | Every five minutes | hot-archive | Expire unreferenced raw data. |
When continuous-native-hours is selected, suspend the standalone projectors
(kube-dc-rbd-payable, kube-dc-native-payable,
kube-dc-managed-fee-payable and kube-dc-kdc-fee-payable). Running both
paths duplicates expensive audits.
Database and scale
- Partitions. The journal is partitioned by month. The receiver creates future partitions ahead of time and checks them regularly. Old partitions can be detached and archived.
- Rows. The collector writes one segment per resource and change, not one row per resource and minute. Hourly rollups keep tenant reads and rating proportional to the hours that changed.
- Connections. Set
PAYG_DB_CONNECTION_LIMITand the matching managed role limit. Use30for a busy installation. - Durability. Plan WAL retention and backups for the evidence volume. See Prepare database durability.
Operate and troubleshoot
| Check | How |
|---|---|
| Collector is running | kubectl -n monitoring logs deploy/kube-dc-metering | grep 'usage collection persisted' shows one line per minute. |
| Billing API is serving | The receiver logged billing schema migrated and billing API serving. GET /api/system/features reports "payg": true. |
| Settlement is progressing | Settlement periods shows current periods as open and past periods moving to finalized after the cutoff. |
| Source hours are proven | Recent hour proof and payable projector Jobs complete. A successful Job is not a complete statement; read its summary. |
Common situations:
- A source was down for an hour. The affected meter-hours are free. The statement lists them with their reason. No action is needed.
- A period stays in
closing. Rating found a gap or an unpriced component. Publish the missing price, or resolve the gap before the period can finalize. - A period cannot finalize because of a conflict. Two sources disagree about ownership or a capture is corrupt. Investigate the named evidence. Never delete evidence to unblock a period.
- A Services release changed the fee writers. The writer-renewal job activates a successor at the next whole hour. Hours before it are free.
- Billing must stop. Suspend the CronJobs through their configuration switches and let running Jobs finish. Suspending a Flux Kustomization does not suspend CronJobs that it already installed. Keep the database and approved statements.
Related pages
- PAYG billing (optional): turn PAYG on and off.
- The billable PAYG profile: select sources, run the preflight and offer paid signup.
- Managed-service fees: set up the fee source.
- Billing plans and resource quota: fixed plans, which work without PAYG.