Cost grows with labels, not traffic — label cardinality and the series count
The app reports one number per interval for each distinct combination of labels, so a metric's cost ignores traffic but multiplies with every label, and one label with unlimited values like customer_id costs more than a 100× traffic spike.
A rule needs numbers to check; before collecting them everywhere, we need to know what one of those numbers costs to keep.
Scene 02
Cost grows with labels, not traffic
- Watch
- Try it
- Predict
- Capture
Why do metrics stay cheap as traffic grows, and what makes them expensive? Watch checkout's traffic climb from 10 to 10,000 requests per second: the log bytes climb with it, and the series count for checkout's request metric (a series is short for time series, one number reported every interval) stays put. Then the on-call engineer needs to know which route is failing, so the number gets tagged, and the tree in the middle starts to multiply.
Highlighted lines are the ones running in the diagram right now.
def handle_request(req):resp = checkout(req)log.write(req, resp)labels = {"service": "checkout","route": req.route,"status": resp.status,"pod": POD_NAME,"customer_id": req.customer_id,}request_count[labels] += 1
every interval: # e.g. every 15 sfor labels, value in request_count.items():send(labels, value, now())
def store(labels, value, ts):series = active.get(labels)if series is None:series = new_series(labels) # ~3 kB (measured)active[labels] = seriesseries.append(ts, value)def check_memory():used = len(active) * SERIES_BYTESif used > memory_budget:crash("out of memory")
Where this sits in Metrics / Monitoring System
Scene 02 of 18, in the Why measure act — Numbers beat complaints; labels, not traffic, set the bill.. The app reports one number per label combination per interval, so a metric's cost ignores traffic and multiplies with every label: one unbounded label like customer_id dwarfs a 100× traffic spike.
Up next. Now that each series is one number the app reports every interval, the next question is what that number should mean, a total so far or a count since the last read, so a missed or repeated read doesn't corrupt it.
All 18 scenes in Metrics / Monitoring System · Every curriculum