Metric Cardinality Management

Comprehensive guide to metric cardinality management for production observability and monitoring systems.

Metrics are the foundation of observability, but high cardinality—many unique time series from a few dimensions—can quickly overwhelm storage, query performance, and alerting. Metric cardinality management is the practice of controlling the number and structure of metric time series to maintain observability at scale. It matters when metric ingestion rates exceed 100k samples per second, when query latency climbs above 500ms under load, or when alerting systems fire dozens of duplicate notifications for the same incident.

Control Cardinality at Ingestion

High cardinality arises when metrics include many dimensions—labels, tags, or fields—each with high uniqueness. A service emitting requests.count with method, status, host, and region labels can generate millions of time series from a single hour of traffic. To prevent cardinality bloat, apply filtering and aggregation at the source.

Use a metric pipeline that collects, transforms, and forwards metrics using a standard protocol such as OpenTelemetry Protocol (OTLP) or Prometheus remote write. A typical metric ingestion system receives data via HTTP, serializes it as JSON, and batches writes to a backend.

Filter and Aggregate Before Ingestion

Before pushing metrics to a backend, reduce cardinality by filtering and aggregating at the edge. This includes dropping low-utility metrics, merging similar series, and downsampling.

For example, emit only the top 100 host values per service and aggregate all others into a __other__ bucket.

{
  "metric": "requests.count",
  "labels": {
    "method": "GET",
    "status": "200",
    "host": "api-341.prod",
    "region": "us-east-1"
  },
  "values": [12.5, 13.2, 14.1],
  "timestamps": [1695481200000, 1695481230000, 1695481260000]
}

The ingestion pipeline should filter out metrics where host appears fewer than 100 times across all services. Use a sliding window or a global count to identify low-frequency labels.

A common failure is misconfiguring the aggregation window: setting a 1-minute window but emitting data every 10 seconds, causing overlap and duplication. This leads to double-counted values and increased cardinality.

Use Labels Strategically

Labels should be selected based on query and alerting patterns. Only include labels that are frequently used in filters, groupings, or joins.

A typical mistake is including every possible dimension—even transient or low-utility ones—without a clear query pattern. For example, including request_id as a label on latency.avg leads to a new time series per request, even though queries rarely group by request_id.

Use a label selection policy: define a list of “core” labels that are always included, and allow dynamic labels to be added conditionally.

metric: latency.avg
core_labels:
  - service
  - method
  - status
dynamic_labels:
  - host
  - region
  - environment
  - deployment_id
  - trace_id

In the pipeline, emit core labels unconditionally. For dynamic labels, include them only if their value appears in a precomputed list of high-utility values.

Optimize Metric Storage and Querying

Once metrics are ingested, storage and querying become the next bottleneck. High cardinality increases the size of metric indexes and the number of time series that must be scanned per query.

Use Compression and Encoding

Store metric data using efficient encoding formats. Use columnar storage with run-length encoding (RLE) and delta encoding for timestamps and values.

For example, in a time-series database, each metric time series is stored as a series of blocks, where each block contains:

When a query selects latency.avg{service="auth",method="POST"}, the database reads only the relevant blocks, skipping others.

A common failure mode is using a flat, row-based storage layout: each sample is stored as a row with timestamp, value, metric_name, and label_key=value pairs. This leads to high I/O and poor cache locality.

Partition by Time and Cardinality

Partition metric data by time and by cardinality to reduce query cost.

For example, partition by day and by service label. Each day’s data is stored in a separate file or directory, and within each day, all series with the same service are stored together.

Queries on service="auth" scan only the auth partition, reducing the number of files read.

A failure mode is using only time-based partitioning, leading to scattered reads when querying across services. Another failure is using coarse-grained partitions: one file per week, but with only 100 series, causing underutilization and cache misses.

Use a partitioning strategy that balances I/O cost and data locality.

Configure Indexing and Materialized Views

Create indexes on frequently queried labels and materialized views for common aggregations.

For example, create an index on service and method for latency.avg queries. This allows fast lookups for latency.avg{service="user",method="PATCH"}.

Materialized views can precompute common aggregations such as:

These views are updated asynchronously, either via batch processing or streaming. Use a system like Apache Kafka or AWS Kinesis to feed raw metrics into a processing pipeline.

A common failure is failing to refresh materialized views: a view becomes stale, returning incorrect results for high-traffic services. The query engine does not detect staleness, so users see outdated data.

Manage Cardinality at Alerting

Alerts depend on metrics, but high cardinality causes alerting to become unwieldy: too many alerts, too many alerts per service, and too many duplicate notifications.

Reduce Alert Scope with Aggregation

Define alerting rules that aggregate metrics across high-cardinality dimensions.

For example, instead of alerting on latency.avg{host=...} for each host, define a rule that computes the average latency across all hosts per service:

alert: service_latency_high
expr: avg(latency.avg) by (service)
for: 5m
threshold: 400ms

This produces one alert per service, regardless of the number of hosts.

A failure mode is using per-host alerts without aggregation. When a service has 1,000 hosts, 1,000 alerts fire simultaneously for the same issue. The alerting system becomes overwhelmed.

Use Hierarchical Alerting

Build a hierarchy of alerts: high-cardinality alerts at the leaf level, with aggregated alerts at higher levels.

For example:

Use a stateful alerting engine that tracks the state of each alert, including:

When a host alert fires, it triggers the parent service alert. When all hosts in a service are down, the service alert fires.

A failure mode is not propagating state changes: a host alert resolves, but the parent service alert remains firing. This causes alert fatigue and confusion.

Implement Alert Deduplication and Merging

Use a deduplication mechanism that merges similar alerts into a single notification.

For example, when multiple host_latency_high alerts fire within 10 minutes, merge them into a single alert with a list of affected hosts.

Use a key derived from service, method, status, and region to group alerts.

The deduplication engine uses a sliding window and compares alert metadata using a similarity function.

A typical failure is using a simple group by without deduplication: alerts are sent for each host, even when the issue is identical.

Detect and Diagnose Cardinality Issues

Cardinality problems often surface as performance degradation or data inconsistency, but they are not immediately visible.

Monitor Cardinality Metrics

Track the number of time series over time. Use a metric such as:

{
  "metric": "metric_series_count",
  "labels": {
    "source": "ingestion",
    "pipeline": "edge"
  },
  "value": 1234567,
  "timestamp": 1695481260000
}

A sudden spike in metric_series_count indicates a cardinality explosion. Correlate it with ingestion rate, query latency, and storage usage.

Use a dashboard that shows:

A failure mode is failing to monitor the number of unique label values per label key. For example, host may have 10,000 values, but region only 20, yet the system treats both equally.

Use Diagnostic Queries and Probes

Write diagnostic queries to identify cardinality bottlenecks.

For example, to find the top 10 most cardinal metrics:

SELECT
  metric_name,
  COUNT(*) as series_count,
  AVG(label_count) as avg_labels_per_series
FROM metric_series
GROUP BY metric_name
ORDER BY series_count DESC
LIMIT 10;

To find label keys with high uniqueness:

SELECT
  label_key,
  COUNT(*) as unique_values,
  COUNT(*) / (SELECT COUNT(*) FROM metric_series) as ratio
FROM metric_series
CROSS JOIN UNNEST(labels) AS label
GROUP BY label_key
ORDER BY unique_values DESC;

A failure mode is using only COUNT(DISTINCT label_value) without examining the distribution of values. A label like deployment_id may have 10,000 distinct values, but 80% of them appear only once—indicating a problem with deployment lifecycle or rollout strategy.

Handle Label Pollution

Label pollution occurs when a metric includes too many low-utility labels—labels with many unique values but little query utility.

A common symptom is a metric with 500,000 time series, but only 500 are used in the top 10 dashboards.

Detect label pollution using a label utility score:

For example, a label trace_id may appear in 5% of all series, but only 20% of queries use it.

Use a tool to identify and flag polluted labels. Then, either:

Maintain Cardinality Over Time

Cardinality is not a one-time task. It requires ongoing maintenance.

Automate Cardinality Audits

Run a daily audit that checks:

Generate a report and send it to observability engineers.

Use a script that runs every 24 hours:

#!/bin/bash


# Query cardinality metrics
curl -s "http://metrics-api:8080/api/v1/query?expr=metric_series_count" > series_count.json

# Extract series count
series_count=$(jq -r '.data.result[0].value[1]' series_count.json)

# Query label utility
label_utility=$(curl -s "http://metrics-api:8080/api/v1/query?expr=avg(label_utility)")

# Write audit log
echo "$(date): Cardinality audit - $series_count series" >> /var/log/cardinality-audit.log
echo "$label_utility" >> /var/log/cardinality-audit.log

A failure mode is running the audit but not acting on it. The report sits in a folder, but no one reviews it.

Evolve Label Strategy Over Time

Review the label strategy quarterly. Identify which labels are used in 80% of queries, and promote them to core labels.

Remove labels that are rarely used or have low utility.

Update metric pipelines to reflect the new label strategy.

When a new service is added, use the core label set by default, with dynamic labels enabled for high-utility dimensions.

A failure mode is using a static label set across all services, even when query patterns vary widely.

This page was rewritten on 18 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.