You stood up a single Prometheus when the platform had three services. Now twelve teams ship their own services, each team wants their own dashboards and alerts, and the central Prometheus is at 18M active series, struggling to evaluate rules within a scrape interval, and someone has filed a ticket asking “can we see all the SLOs in one place.” The instinct is to scale the central Prometheus harder. The right move is federation — and if you don’t plan the cardinality before you plan the topology, you reproduce the same problem one layer up.
What’s happening
Federation in Prometheus is a scrape_config that targets another Prometheus’s /federate endpoint with a series selector. The scraping server pulls a subset of series from the scraped server. The naive use is “let’s federate everything to a global Prometheus” — which means the global server’s cardinality is the sum of every team’s cardinality, you’ve solved nothing, and you’ve added a second copy of the data on top.
The pattern that actually works is hierarchical federation with explicit budgets:
- Per-team Prometheus owns the raw, high-cardinality data: every label, every microservice, every histogram bucket. Retention is short (15-30 days). Alerts that need raw data live here. The team operates this server and is responsible for the cardinality.
- Global Prometheus federates only pre-aggregated series — recording rules that have already collapsed cardinality by dropping high-fan-out labels. The global server holds maybe 5% of the underlying data volume. Cross-team dashboards, SLO rollups, capacity planning queries run here.
The global view never sees raw per-pod, per-handler, per-customer series. It sees slo:request_error_ratio:5m{service="payments"} — one series per service per SLO, not one per pod-handler-status combination.
How to verify
Active series per Prometheus server:
prometheus_tsdb_head_series
Per team, this number should fit a budget you committed to in writing. A reasonable starting budget for a healthy single-Prometheus team is 2-5 million active series. Above that, the team needs to either shard their Prometheus or kill cardinality.
What the global Prometheus actually has:
prometheus_tsdb_head_series{instance="global-prom:9090"}
If this exceeds 1-2 million, federation is pulling too much. Check the /federate URL on the scrape config — it almost certainly has a permissive matcher like {__name__=~".+"} instead of a match[] restricted to recording rules.
Top cardinality contributors on a team Prometheus:
curl -fs http://team-prom:9090/api/v1/status/tsdb | jq '.data.seriesCountByMetricName | .[0:20]'
The classic offenders: HTTP histograms with a customer_id label, Kubernetes pod metrics with pod (high churn from autoscaling), path labels that include UUIDs or session tokens, and anything tagged by commit_sha.
The pattern
Per-team Prometheus scrape config (writes recording rules into a high-namespace):
# /etc/prometheus/rules/team-payments.yml
groups:
- name: payments-aggregates
interval: 30s
rules:
- record: team_payments:request_total:rate5m
expr: sum by (service, status) (rate(http_requests_total{team="payments"}[5m]))
- record: team_payments:request_errors:rate5m
expr: sum by (service) (rate(http_requests_total{team="payments",status=~"5.."}[5m]))
- record: team_payments:request_latency:p99_5m
expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{team="payments"}[5m])))
- record: team_payments:slo:error_ratio:5m
expr: team_payments:request_errors:rate5m / clamp_min(team_payments:request_total:rate5m, 1)
Note the namespace prefix team_payments: — every recording rule produced for federation must be prefixed by team so the global server’s metric names don’t collide. This is a discipline thing; nothing enforces it but a code review.
Global Prometheus federation scrape (pulls only the prefixed rules):
# /etc/prometheus/prometheus.yml on the global server
scrape_configs:
- job_name: 'federate-team-payments'
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{__name__=~"team_payments:.+"}'
scrape_interval: 30s
scrape_timeout: 20s
static_configs:
- targets: ['team-payments-prom.internal:9090']
labels:
team: 'payments'
- job_name: 'federate-team-search'
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{__name__=~"team_search:.+"}'
scrape_interval: 30s
scrape_timeout: 20s
static_configs:
- targets: ['team-search-prom.internal:9090']
labels:
team: 'search'
The match[] restriction is the whole point. Without it federation imports every series; with it, the global server only sees what teams have explicitly published.
Cardinality budgets that hold
Budgets only work if they’re enforced. Three mechanisms, in increasing strictness:
- Visibility. Every team has a dashboard that shows their own
prometheus_tsdb_head_seriesagainst a line at their budget. When the line is crossed, a ticket auto-creates against the team backlog. Not an alert at 3am — a ticket at 9am. - Sample limits at scrape time. Set
sample_limitandbody_size_limiton the scrape config. A target that exceeds the limit is dropped from that scrape and you getup == 0. This is harsh and breaks things, but it’s the only way to stop a runaway exporter from taking down the Prometheus. - Hard cap on the federate endpoint. The global Prometheus’s
match[]should be deny-by-default — only the explicitteam_*:prefixes are allowed. New aggregates require explicit addition to the global config, which is a code review, which is the moment someone notices the cardinality cost.
A reasonable starting budget structure: per-team server ≤ 5M active series, global server ≤ 2M active series, single recording rule ≤ 50K series per evaluation. These aren’t laws of physics; they’re numbers we’ve found hold up at the typical team size on cloud VMs without surprising operational pain.
What goes in the global view, what stays per-team
In the global view:
- SLO/error-budget series per service.
- Aggregate throughput, latency percentiles, saturation per service (no per-pod, no per-instance).
- Cross-service request flow rates for capacity planning.
- Infra-level metrics already aggregated: node CPU/memory percentiles per cluster.
Stays per-team only:
- Raw per-pod, per-instance, per-customer metrics.
- Histogram buckets in full detail (only the percentile recording rules leave).
- High-churn labels:
pod,container_id,commit_sha,build_id. - Anything with a
customer_idortenant_idlabel unless explicitly published as an aggregate.
If a team needs cross-team data at raw resolution, they query the per-team Prometheus directly (via Grafana datasources for each), not through the global one. Global is for the executive view and SLO rollups, not for incident triage.
If you want federation that’s actually planned — recording rule namespaces, cardinality budgets, and per-team Prometheus sized to real workload — our monitoring + on-call team designs and operates this under environment management. Book a cardinality review.