07

Metric Cardinality as a Platform Constraint

Source: “Building an Observability Platform: From Prometheus to Mimir, Loki, Tempo, and Grafana” — Chapter 7, “Cardinality: The Central Constraint of Metrics”

The enterprise problem and today’s slice

Enterprise problem: Every unique metric label combination consumes memory, CPU, disk, network, and query capacity, so one unbounded identifier can destabilize the shared metrics platform and delay incident response for every team.

Whole-course context: The working Prometheus queries and notification routes are incoming evidence; today governs the series identities those queries and rules depend on.

Today’s slice: Model cardinality multiplication, set per-metric and per-tenant budgets, move event identity to logs or traces, and contain unsafe instrumentation before ingestion.

End-of-day evidence: A cardinality review with estimated and observed series counts, rejected dangerous labels, approved alternatives, and a budget-enforcement drill with an unaffected tenant control.

Still unsolved: Central multi-cluster retention, distributed ingestion and query scaling, and the architecture beyond local Prometheus remain deferred.

Customer use cases

Teams need useful dimensions, but an unrestricted label API transfers the cost and failure risk to everyone sharing the backend. These cases preserve operational questions while enforcing economic limits.

Use case IDActorCustomer jobSuccess outcomeDenial or recovery evidence
D07-UC-01Service developerAdd a metric dimension that supports a named aggregate questionReview estimates its value set and combinations, then accepts the bounded label or directs detail to another signalLabels such as customer ID, request ID, raw URL, or exception text are rejected with a replacement design
D07-UC-02Metrics platform operatorKeep tenant series growth within capacity without hiding useful service healthBudgets, dashboards, and limits identify growth before platform saturationA noisy tenant is contained and an unrelated tenant remains queryable within objective

Actor-centred user stories

“Low cardinality” is not measurable, so stories require bounded value sets, observed counts, and a safe denial path.

Story IDUse case IDsUser storyObservable acceptance conditions
D07-US-01D07-UC-01As a service developer, I want a label review before release, so that my metric answers an aggregate question without creating a series per eventThe review records dimension bounds, product estimate, owner, query examples, and alternative signal for rejected detail
D07-US-02D07-UC-02As a platform operator, I want per-tenant series budgets and growth alerts, so that one service cannot exhaust shared metrics capacityThe drill crosses one tenant’s threshold, blocks or drops unsafe series visibly, and leaves the control tenant healthy

End-to-end product flows

Cardinality damage often appears only after deployment, so the flows combine pre-release estimation with observed production enforcement.

Flow IDUse case IDsPathTriggerNumbered stepsTerminal evidence
D07-FLOW-01D07-UC-01HappyDeveloper proposes a failure_category label1. Name the operational query.<br>2. Enumerate bounded values.<br>3. Multiply dimensions and deployment scope.<br>4. Compare with budget.<br>5. Run load test.<br>6. approve revision.Actor, metric revision, value bounds, estimated and observed series, queries, budget, environment, timestamp, and approval ID
D07-FLOW-02D07-UC-01DeniedDeveloper proposes customer_id as a metric label1. Calculate worst-case combinations.<br>2. Reject the label.<br>3. preserve customer ID in authorized logs or traces.<br>4. replace with bounded customer tier if needed.<br>5. re-run review.Rejection reason, estimate, replacement schema, access boundary, revised series count, and review ID
D07-FLOW-03D07-UC-02RecoveryTenant active-series count exceeds its budget1. Identify new series source.<br>2. enforce tenant limit.<br>3. notify owner.<br>4. roll back instrumentation or relabel.<br>5. verify queries recover.<br>6. probe another tenant.Limit event, offending label set, remediation, recovery time, control-tenant latency, and immutable incident ID

System design derived from the flows

If enforcement exists only in documentation, one accidental deploy can create millions of series. The design joins review-time estimates, runtime observation, tenant limits, and reversible remediation.

Use case IDEntry pointResponsible servicesAuthoritative storeFailure evidence
D07-UC-01Instrumentation review workflowMetric catalogue, cardinality estimator, schema validator, load-test runnerMetric catalogue owned by metrics platformUnbounded value set, budget excess, missing query, or observed count beyond estimate
D07-UC-02Tenant capacity dashboard and limit APISeries analyzer, ingestion limiter, relabel controller, notification serviceTenant budget store owned by metrics platformLimit rejection, active-series spike, query latency breach, or control-tenant impact

Data model and ownership

Budgets cannot be enforced consistently if metric schemas and exceptions live in chat messages. Durable revisions tie each label decision to an owner, limit, and lifecycle.

Generated-application database: Not created in this slice — metric governance and evidence live in platform control stores; no application-domain database is required.

Record or entityStore and ownerPrimary keyForeign key or opaque referenceTenant keyMaterial constraintLifecycle and deletionUse case IDs
MetricSchemaRevisionMetric catalogue, metrics platformmetric_schema_revision_idOpaque service and source commit referencesorganization_idMetric name, type, unit, label names, bounded values, and owner are immutable per revisionVersioned through service life; tombstoned after retention and query migrationD07-UC-01
CardinalityReviewGovernance store, metrics platformcardinality_review_idmetric_schema_revision_id local FKorganization_idNamed query, formula, estimate, observed test count, and decision are requiredRetained with schema history; raw load-test samples expire separatelyD07-UC-01
TenantSeriesBudgetCapacity store, metrics platformtenant_budget_idOpaque plan or capacity revisionorganization_idOne active budget per tenant and environment; exceptions require expiryVersioned; superseded budgets retained for audit then expiredD07-UC-02
LimitEventIngestion evidence store, metrics platformlimit_event_idOpaque tenant budget and series fingerprint referencesorganization_idReason, measured count, threshold, and disposition are append-onlyRetained through incident review; detailed label samples redacted and expiredD07-UC-02

Series multiply

Label costs are easy to underestimate because dimensions multiply rather than add. For one metric with 30 services, 4 environments, 5 regions, 200 routes, 10 status codes, and 6 methods, the theoretical upper bound is:

30 × 4 × 5 × 200 × 10 × 6 = 7,200,000 series

Adding 100,000 customer IDs does not add 100,000 series; it can multiply the existing space by 100,000. Real combinations may be sparse, but a safety review cannot assume sparsity without observed evidence and a reason it remains bounded.

Series cost is broader than storage. Each active series requires ingestion bookkeeping, memory for current chunks and indexes, network transfer, compaction work, and query matching. High churn—many short-lived label values—adds further pressure even when the simultaneous count seems tolerable.

Put identity in the right signal

Metrics become unsafe when they carry event identity, so divide evidence by representation.

EvidenceCorrect homeReason
Service, environment, region, operation, status classMetric labelsBounded dimensions support aggregation
User, email, order, request, session, raw URLStructured logs with access controlsIndividual event identity is searchable without one series per value
Request and parent relationshipTrace contextPreserves distributed causality
Function and stack resource attributionProfilesMaps cost to code locations

Replace raw routes such as /orders/8128 with templates such as /orders/{order_id}. Replace exception messages with a bounded failure category while keeping the detailed exception in logs.

Budgets and enforcement

Review alone cannot stop runtime churn, so govern at several layers. SDK views can drop unsafe attributes. Collector processors or Prometheus relabeling can remove known hazards. Ingestion systems can enforce active-series and rate limits per tenant. Platform dashboards should show top metrics and labels by series count, churn, sample volume, and growth.

Avoid silent correction. When a label is dropped or a tenant is limited, emit attributable evidence and notify the owner. A hidden drop can make a dashboard look healthy while discarding failures.

A temporary exception needs scope, owner, justification, capacity impact, and expiry. Permanent exemptions become undocumented platform architecture.

Practical cardinality review

A static estimate can miss generated values, so combine code review with representative load.

  1. List every metric and label introduced by the revision.
  2. State the operational query each label enables.
  3. Bound values per deployment unit and multiply combinations.
  4. Include replicas, clusters, regions, and tenant count.
  5. Run representative traffic and compare observed series with the estimate.
  6. Inject an unbounded test label and prove the policy rejects or removes it visibly.
  7. Verify another tenant’s query latency remains within objective.

Key takeaways

Cardinality is a product and reliability constraint, not an after-the-fact storage concern.

  • Every unique label set creates a time series.
  • Dimensions multiply and scale again across replicas, clusters, and tenants.
  • Unique event identity belongs in logs or traces, not metric labels.
  • Review-time estimates need runtime series and churn measurements.
  • Limits require visible denial evidence and tenant-isolation controls.

Checklist

Use this checklist for every instrumentation revision.

  • [ ] Every label supports a named aggregate query.
  • [ ] Value sets are bounded or the label is rejected.
  • [ ] The estimate includes deployment and tenant multipliers.
  • [ ] Raw URLs, IDs, emails, and exception messages are absent from labels.
  • [ ] Observed active series and churn match the expected order of magnitude.
  • [ ] Limits and remediation are tested with an unaffected tenant control.

Sources

These official references define Prometheus label identity and current cardinality guidance.