Ch. 8 · Spring Boot

Spring Metrics Tags and Cardinality

Spring Metrics Tags and Cardinality. Learn the reasoning, a practical example, common mistakes and an interview exercise.

~2 min readadvancedupdated Oct 3, 2026

Metrics tags multiply time series. Use bounded categories rather than unique user or request identifiers.

Before you start

You should know Java classes, dependency injection and basic HTTP requests. Identify where a call crosses a framework-managed boundary. The snippets illustrate a focused mechanism; database configuration, application wiring and authentication must be supplied by the surrounding application when applicable.

The practical goal is to reason through this situation: Status class and route template are bounded; raw URL IDs can create unbounded labels. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.

Step-by-step walkthrough

Step 1: Estimate series multiplication

Every distinct tag combination creates another metrics series.

Step 2: Use bounded dimensions

Route templates and status categories are safer than raw IDs and full URLs.

Step 3: Put unique detail elsewhere

Use correlated logs or traces for individual request investigation.

Worked scenario

Status class and route template are bounded; raw URL IDs can create unbounded labels.

A requests counter tagged with user ID grows with every user; adding request ID makes almost every event another series. Tagging the route template /users/{id} preserves aggregate usefulness. Logs and traces can hold the particular ID without multiplying aggregate time series.

Common mistake

High-cardinality tags increase storage and degrade monitoring usefulness.

Verify the behavior

Generate many distinct IDs and verify metric series count remains bounded by the intended categories.

Interview exercise

Correlate one failed request.

Answer and reasoning

Use logs and traces with a correlation ID instead of adding every request ID as a metrics label.

Continue learning

Compare the scenario with the Spring Boot interview questions and test your understanding with the Spring Boot MCQs. For terminology and implementation details, consult the reference material.

More in Spring Boot

read ✓Spring Boot · hard

Spring @Async and Executor Configuration

Run methods asynchronously with @Async, configure a bounded executor, and handle exceptions and the proxy boundary.

~2 min readread →
read ✓Spring Boot · hard

Spring Boot Caching Abstraction

Cache method results with @Cacheable, choose keys and TTLs, and evict on writes without the self-invocation trap.

~2 min readread →
read ✓Spring Boot · hard

Spring Declarative HTTP Clients

Define outbound HTTP as an annotated interface with @HttpExchange, create the proxy, and configure timeouts and errors.

~2 min readread →
esc