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.