CLOUD CONCEPT

Metric Cardinality

Metric cardinality is the number of distinct time series created by metric names and their unique combinations of dimension or label values.

Cloud Concepts Hub →

What is Metric Cardinality

A metric such as request latency becomes many separate time series when it is partitioned by service, environment, endpoint, or instance. Controlling cardinality preserves useful diagnostic detail while limiting ingestion volume, storage costs, query work, and operational complexity.

Metric cardinality describes how many distinct metric time series a monitoring system must handle within a defined scope and time window. A series is typically identified by a metric name and a complete set of dimension or label name-value pairs. Additional boundaries, such as a namespace, account, or Region, can also distinguish metrics. Cardinality is not the number of samples: one series containing a million measurements still has a cardinality of one.

Dimensions multiply the potential number of series. Suppose a request-count metric has three environment values, four service values, and twenty endpoint values. If every combination occurs, that metric produces 240 series. Adding an instance identifier with fifty possible values could increase the theoretical total to 12,000. Actual cardinality depends on which combinations are emitted, not simply on multiplying every value observed independently. Continually changing instance or container identifiers also create series churn, increasing the number of distinct series seen over time.

In cloud architectures, choose dimensions that support specific operational decisions. Environment, service, availability zone, and normalized endpoint often provide useful breakdowns. Request IDs, session IDs, arbitrary URLs, and user IDs can produce unbounded growth. For example, use the route template /orders/{orderId} rather than a separate dimension value for every order URL. Keep request-specific identifiers in logs or traces so engineers can investigate individual failures without creating a metric series for every request.

Amazon CloudWatch illustrates the identity rules tested in certification questions. Within an account and Region, a metric is identified by its namespace, metric name, and dimensions. Namespaces separate metric identities; they do not automatically aggregate measurements. CloudWatch supports up to 30 dimensions per metric, but that limit does not make high-cardinality values safe. Changing a dimension value or adding a dimension creates a different metric identity.

CloudWatch does not automatically aggregate custom metrics across dimensions. If an application publishes RequestCount with Service and InstanceId, requesting RequestCount with only Service does not retrieve an automatically stored service-level total. Publish an explicit rollup or use an appropriate query or metric-math expression over the underlying series. Some AWS service metrics offer predefined aggregations, so do not assume their behavior applies to custom metrics. Query-time aggregation can simplify results without reducing the cardinality already ingested.

Resolution and cardinality are separate design choices. CloudWatch standard-resolution custom metrics use 60-second resolution, while high-resolution custom metrics support one-second resolution. Publishing more frequently to an unchanged metric identity increases sample volume, not cardinality. Conversely, adding unique request identifiers increases cardinality even if each series receives only one sample. Costs depend on the monitoring service's pricing model, including custom metric counts, ingestion, storage, queries, and alarm configuration.

Control cardinality before ingestion by allowlisting dimensions, normalizing values, dropping unnecessary labels, and aggregating measurements at the required operational level. Preserve meaningful statistics during aggregation: summing request counts is appropriate, but averaging instance-level averages without sample counts can misrepresent latency. Maintain distributions or suitable histogram data when percentile analysis matters. Review both active series and series churn, and test instrumentation changes against realistic fleet size and traffic diversity before deploying them.

Key aspects of Metric Cardinality

Effective cardinality management combines explicit series identity, bounded dimensions, deliberate aggregation, and separate control of sampling frequency and series churn.

Series identity

A metric name and its full dimension or label set distinguish one series from another. Namespace and platform-specific boundaries also matter, so identically named metrics are not necessarily the same metric.

Combinatorial growth

Each additional dimension can multiply the number of series when its values occur across existing combinations. Estimate the combinations actually emitted rather than treating the number of dimension names as the cardinality.

Bounded dimension values

Prefer controlled values such as deployment environment or normalized route. Put unbounded identifiers in logs or traces unless a specific monitoring requirement justifies their metric cost.

Aggregation placement

Aggregation before ingestion can reduce stored series, while aggregation during queries generally only reduces the returned results. Explicitly design rollups and retain the counts or distributions needed for statistically correct calculations.

Independence from resolution

Measurement frequency controls samples per series, not the number of distinct series. Evaluate collection interval and cardinality separately because they affect different resource and billing dimensions.

Series churn

Short-lived resources can generate many distinct series even when only a small number are active simultaneously. Track cardinality over a defined interval and avoid unnecessary ephemeral resource identifiers.

Cloud services for Metric Cardinality

CloudWatch provides operational metrics and alarms, while CloudWatch Logs retains detailed events for investigations that require request or user context. When deriving metrics from logs, extract bounded dimensions rather than copying every event attribute into metric identity. Amazon Managed Service for Prometheus applies the same cardinality principles to label-based telemetry. Across these services, normalize or filter dimensions before ingestion, retain detailed context in logs, and distinguish stored rollups from query-time aggregation. This separation supports useful alerts and troubleshooting without making every unique event a separate metric series.

Amazon CloudWatch image Amazon CloudWatch

CloudWatch distinguishes metrics by namespace, metric name, and dimensions within an account and Region. Custom metric dimension combinations affect metric counts and costs; high-resolution publishing changes measurement granularity rather than metric identity.

Open Amazon CloudWatch →
Amazon Managed Service for Prometheus image Amazon Managed Service for Prometheus

Amazon Managed Service for Prometheus stores series identified by metric names and label sets. Label selection and filtering before remote write can reduce ingested cardinality; recording rules create derived series but do not remove the original ingested series.

Open Amazon Managed Service for Prometheus →