# Metrics and monitoring - cardinality is the thing that kills you

> Why one label with unbounded values takes down the system that was supposed to explain the outage. THE CARDINALITY LIMITER IS DRAWN RED BECAUSE ITS SUCCESS…

Source: https://tierslate.com/templates/metrics-monitoring

Data & analytics · System design · core · 9 step walkthrough · 5 tables

Why one label with unbounded values takes down the system that was supposed to explain the outage.

**Own this board: 400 credits.** The first act plays on the page. Owned once with credits, never a subscription.

## What this board gets wrong on purpose

The tension: THE CARDINALITY LIMITER IS DRAWN RED BECAUSE ITS SUCCESS AND ITS FAILURE LOOK IDENTICAL. When a team ships a label with a user id in it, the limiter starts rejecting that tenant's writes - which protects everyone else and means the team instrumenting a new feature sees gaps in a dashboard and assumes their code is broken. There is no good place to put that pain, and a limiter that fails open takes the whole cluster down instead. The retention tiers have the same shape of problem: a five-minute rollup cannot answer a question about a thirty-second spike, so every query beyond fifteen days is quietly answering a different question than the person asked, and nothing in the UI says so. And the alerting floor is the scrape interval - thirty to sixty seconds from condition to page - which no amount of engineering below that layer improves, but which every incident review asks about anyway.

## Practise this as an interview

Take Metrics and monitoring - cardinality is the thing that kills you as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.

## Start here

### Why this design

Metrics and monitoring separates people who have run a time series database from people who have drawn one. Interviewers use it to probe whether you know that the unit of cost is the SERIES and not the sample, that one unbounded label can take the cluster down during the incident it should explain, and that retention tiers trade storage for questions you can no longer ask. Almost every team running Prometheus-style monitoring at scale has had the cardinality outage at least once, which is why this board is built around it.

### What you will learn

- Why active series - 3,000 instances x 500 metric names x 6 label sets = 9 million - and not 600,000 samples/s is the number that sizes the system.
- How one user_id label takes 9M series to 79M in a week and the index from 31.5 GB to 277 GB of memory, with every sample valid and the disk barely moving.
- Why the limiter caps ACTIVE SERIES per tenant, fails closed, and still looks like a bug to the team it rejects.
- How delta-of-delta and XOR encoding take a 16 B sample to 1.7 B, and how 15 s / 5 min / 1 h tiers make two years of storage 19.6x cheaper.
- What a downsample can no longer answer: the shape of a spike, and any p99 built by averaging p99s.
- Why alert latency has a floor of scrape plus evaluation interval, so a \`for: 2m\` rule pages two and a half to three minutes after the condition.

### How to read this board

1. Press play once: nine steps follow one sample from a counter in process memory to a page on somebody's phone.
2. PRODUCE, then SCRAPE & ADMIT: the 15 s scrape, the ingest gateway, and the red cardinality limiter whose refusal wire goes backwards.
3. WRITE PATH · MEMORY FIRST: write-ahead log, head block, and the red inverted label index - the part that actually breaks.
4. RETENTION TIERS · THE COST MODEL: raw blocks, the compactor, the 5-minute and 1-hour tiers.
5. SERVE & ALERT: the query frontend's per-query series limit, the result cache, and the rule evaluator.
6. Pages 1 to 6 in order: requirements, capacity, storage, availability, how it works, deployment.
7. DATA MODEL: metric names, label names, series, retention tiers and cardinality incidents - what a series costs, and who added it.

## 1 · Requirements

### Ask these before drawing anything

- How many machines, processes and containers, and how fast does that number change? A fleet that redeploys twenty times a day creates a new pod id every time, and if pod id is a label, every deploy is a cardinality event.
- Who is allowed to define a metric, and does anyone review it? If any engineer can add a label in a pull request nobody from this team reads, the limiter is not a safeguard, it is the review process.
- What is the alerting latency anybody actually needs? The floor is the scrape interval plus the evaluation interval. Asking for five seconds means scraping every five seconds, which is four times everything.
- How far back do people query, and at what resolution? "A year" and "a year at 15-second resolution" differ by a factor of two hundred and forty in storage.
- Is this multi-tenant? If yes, one tenant can take out every other tenant, and per-tenant limits stop being nice-to-have.
- Are these metrics or are they events? If somebody wants to know which user hit the error, they want logs or traces, not metrics, and giving them a label is how the system dies.

### Functional

- Scrape every instance every 15 seconds and store every sample with its timestamp and its full label set.
- Answer range queries over any time window with aggregation, rate and quantile functions.
- Evaluate alerting rules every 30 seconds and notify when a condition has held for a stated duration.
- Downsample automatically into a 5-minute and a 1-hour tier and expire the raw samples on schedule.
- Enforce a per-tenant active series limit, reject over it, and make the rejection visible to the tenant rather than only to the platform team.
- Let anyone see the cardinality of their own metrics, by metric and by label, without asking the platform team.

### Non-functional

- The monitoring system must be more available than the systems it monitors - 99.9 percent - and must not share their dependencies. A metrics stack that runs on the cluster it watches is blind during exactly the outage that matters.
- Query p95 under 1 second for a 6 hour window, under 10 seconds for a 30 day window.
- Ingest must not be affected by query load. One expensive query must not delay a write, which is why the read and write paths are separate fleets rather than one process.
- An alert fires within 60 seconds of its condition becoming true, and that number is the scrape interval plus the evaluation interval, not a target anyone can tune.
- No single tenant may consume more than 10 percent of cluster memory, enforced rather than requested.

### Out of scope

- Logs and traces. They answer "which request" and metrics answer "how many", and the most expensive mistake in this whole category is using one for the other.
- Long-term analytics over metrics. Two years of hourly rollups is for capacity planning, not for a business report.
- Anomaly detection. Worth having, worth building second, and it changes none of the arithmetic here.

## The rest of this board

This page publishes the question. The answer - 5 more written pages, a 9-step narrated walkthrough and a 5-table schema - is the board itself, and it opens in Tierslate.

- 5 written pages
- 9 walkthrough steps
- 5 tables (37 columns)

5 pages behind this one:

- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan

## Related system design templates

- [Ad serving system design](https://tierslate.com/templates/ad-serving) - Why a system with eighty milliseconds to decide must spend money it cannot yet count.
- [Analytics pipeline system design](https://tierslate.com/templates/analytics-pipeline) - Why a click takes ten seconds to reach one dashboard and until tomorrow to reach the one people trust.
- [Log aggregation system design](https://tierslate.com/templates/log-aggregation) - Why searching your logs costs thirteen times more than keeping them, and what you can no longer ask once you sample.
- [Recommendation engine system design](https://tierslate.com/templates/recommendation-engine) - Why the feed is computed in a hundred milliseconds by a model that is a day out of date.
- [Leaderboard system design](https://tierslate.com/templates/leaderboard) - How a sorted set answers top ten and my rank in milliseconds, and why rank is computed rather than stored.
- [Search autocomplete system design](https://tierslate.com/templates/typeahead-autocomplete) - Why suggestions come from a precomputed prefix index, and why freshness is traded for speed on every keystroke.
- [View counter system design](https://tierslate.com/templates/view-counter) - Why a counter on a hot row is batched in memory, and how much of the count you may lose on a crash.
- [Uptime monitor and status page system design](https://tierslate.com/templates/status-page) - Why uptime is measured from many regions outside your network, and why the status page must not share its fate.
- [A/B testing platform system design](https://tierslate.com/templates/ab-testing) - How users are bucketed deterministically, and why exposure logging and metric pipelines decide whether a result is real.
- [ETL and the data warehouse system design](https://tierslate.com/templates/etl-warehouse) - Why batch loads trade freshness for correctness, and how late data and reruns are made safe.
- [Full-text search system design](https://tierslate.com/templates/full-text-search) - How an inverted index answers a query across shards, and why the slowest shard sets every response time.

All 100 system design templates: https://tierslate.com/templates (Markdown: https://tierslate.com/templates.md)
