One Prometheus cannot scrape 5000 targets. How do you scale scraping horizontally?
AdvancedScenarioPrometheus and PromQL at Scale
Answer
Situation read → A single Prometheus has CPU, memory and scrape-time limits. Scale by splitting the target set, not by adding replicas that scrape the same targets.
What I'd do →
- Functional sharding: one Prometheus per team, environment or job type.
- Hash-based sharding with relabeling:
relabel_configs:
- source_labels: [__address__]
modulus: 4
target_label: __tmp_hash
action: hashmod
- source_labels: [__tmp_hash]
regex: ^1$ # this instance keeps shard 1
action: keep
- The Prometheus Operator supports
shards: 4natively. - Put a global query layer on top (Thanos Querier, Mimir, VictoriaMetrics) because each shard sees only part of the data.
- Run HA pairs per shard.
Why → Hashing gives an even, stable split. Global queries then need a layer that merges shards.
Interview tip → Before sharding, check whether cardinality, not target count, is the real problem.
More on Prometheus and PromQL at Scale
Prometheus memory has grown to 60 GB and keeps climbing. How do you find the cause?IntermediateA developer added `user_id` as a metric label. What is the problem and what do you advise?BeginnerYour dashboard shows the average of per-pod p99 latencies. Why is it wrong, and how do you compute a correct fleet-wide p99?IntermediateChoose histogram bucket boundaries for a service with a 300 ms latency SLO.AdvancedYou have 500 short-lived batch jobs that finish before Prometheus can scrape them. How do you capture their metrics?IntermediateYour EC2 fleet autoscales constantly. How do you keep Prometheus targets up to date?Intermediate