How Prometheus Federation Works: Architecture, Mechanics, and Scaling Strategies
Prometheus federation allows a Prometheus server to scrape selected metrics from other Prometheus servers, enabling hierarchical, scalable monitoring architectures that bypass the limitations of single-node collection limits and facili...
Prometheus federation allows a Prometheus server to scrape selected metrics from other Prometheus servers, enabling hierarchical, scalable monitoring architectures that bypass the limitations of single-node collection limits and facilitate cross-network visibility.
Contents
In complex, enterprise-grade cloud-native environments, monitoring infrastructure often scales to hundreds of thousands of active targets, millions of active time series, and multiple isolated network zones or Kubernetes clusters. A single Prometheus server, while exceptionally capable, eventually hits CPU, memory, and storage bottlenecks when attempting to handle global collection, rule evaluation, and long-term storage concurrently. This is where the concept of federation becomes essential. Rather than deploying a monolithic scraper that attempts to pull data from every corner of a global infrastructure, organizations use a multi-tiered topology. Lower-level Prometheus servers scrape local targets directly at high frequencies, while a higher-level global Prometheus server periodically pulls aggregated, filtered, or summarized time series data from the lower-tier instances.
Understanding how this mechanism functions under the hood requires examining its underlying HTTP endpoints, data models, configuration syntax, and the operational trade-offs that accompany distributed metrics collection.
The Core Architecture of Prometheus Federation
The standard Prometheus architecture relies on a pull-based model where individual servers scrape targets via HTTP endpoints exposed in the OpenMetrics or Prometheus text-based exposition format. Federation extends this pull model so that a Prometheus server can act as both a scraper of application targets and a target itself for another Prometheus server.
In a federated topology, servers are typically categorized into two roles:
Leaf (or Edge) Prometheus Servers: These instances reside close to the workloads, often running within specific Kubernetes clusters, regional data centers, or isolated virtual private clouds (VPCs). They perform high-frequency scraping of local applications, infrastructure exporters, and system metrics. They evaluate local alerting and recording rules and maintain local time-series databases (TSDBs).
Global (or Central) Prometheus Servers: These instances sit at the top of the hierarchy. Instead of scraping raw application targets, they execute HTTP GET requests against the
/federateendpoint of the leaf Prometheus servers. They pull subsetted, pre-aggregated, or downsampled metrics to generate global dashboards, drive organization-wide alerting, or forward data to long-term storage solutions.Application A (Scrape) -> Leaf Prometheus 1
Application B (Scrape) -> Leaf Prometheus 2
Leaf Prometheus 1 & 2 -> HTTP GET (/federate) -> Global Prometheus Server
This hierarchical approach decouples local collection performance from global reporting. If a global Prometheus server experiences network partitions or temporary downtime, the leaf servers continue scraping, evaluating rules, and storing data locally without data loss at the edge.
Mechanics of the /federate Endpoint
At the heart of federation is the /federate HTTP endpoint exposed by every Prometheus server. When a global Prometheus server scrapes a leaf server, it does not download the entire database. Instead, it queries this specific endpoint, passing a set of matchers as URL query parameters to filter the returned time series.
Matchers and Parameter Structure
A federation request requires at least one match[] parameter. These parameters use standard Prometheus vector selectors. For example, a global server might send a request structured like this:
GET /federate?match[]={job="api-server"} GET /federate?match[]={__name__=~"job:.*"} GET /federate?match[]={env="production",tier="backend"}
When the leaf server receives this request, it evaluates the matchers against its local TSDB in-memory chunks and active series. It then serializes the matching time series into the standard Prometheus exposition format and returns them with an HTTP 200 OK status.
Handling Timestamps and Staleness
Unlike standard scraping where Prometheus assigns the scrape timestamp at the exact moment of ingestion, federated scrapes respect the timestamps of the samples as they were ingested by the leaf server. This ensures that even if network latency introduces a slight delay in the global server's pull loop, the chronological integrity of the historical data point is preserved.
However, handling staleness in federated architectures requires careful consideration. If a leaf server stops receiving metrics from a target, it marks the series as stale. During the next federated scrape, that staleness marker is passed up to the global server. If the global server is configured with a scrape interval that is too slow relative to the leaf server's scrape interval, transient gaps can occur, or metrics may appear to linger longer than intended.
Configuring Prometheus Federation
Setting up federation requires configuration changes on the global (scraping) Prometheus server. The leaf servers require no special configuration changes other than ensuring network accessibility and appropriate firewall rules to allow incoming HTTP traffic on their web port (typically port 9090) from the global server's IP address.
Below is an example snippet of a prometheus.yml configuration file for a global Prometheus server scraping two leaf instances located in different regions:
scrape_configs: - job_name: 'federate-region-us-east' scrape_interval: 15s honor_labels: true metrics_path: '/federate' params: 'match[]': - '{job=~"kubernetes-nodes|kubernetes-pods"}' - '{__name__=~"prometheus_rule_evaluation_failures_total|job:http_requests_total:rate5m"}' static_configs: - targets: - 'prometheus-us-east.internal.example.com:9090' - job_name: 'federate-region-eu-west' scrape_interval: 15s honor_labels: true metrics_path: '/federate' params: 'match[]': - '{job=~"kubernetes-nodes|kubernetes-pods"}' - '{__name__=~"prometheus_rule_evaluation_failures_total|job:http_requests_total:rate5m"}' static_configs: - targets: - 'prometheus-eu-west.internal.example.com:9090'
Understanding honor_labels
One of the most critical configuration parameters in a federation setup is honor_labels.
- When
honor_labels: false(Default): If a metric scraped from a leaf server already contains a label that conflicts with labels automatically assigned by the global server (such asjoborinstance), Prometheus renames the conflicting label on the leaf metric by prefixing it withexported_. For example,instance="app-pod-1"becomesexported_instance="app-pod-1", and the global server assigns its own target instance label. - When
honor_labels: true: Prometheus respects the original label values coming from the leaf server. If a collision occurs, the global server keeps the leaf server's label value and discards or ignores the conflicting label from its own scrape configuration. In hierarchical setups,honor_labels: trueis almost always required to preserve the original source identity (instance,job, and custom metadata) of the monitored workloads.
Filtering and Reducing Cardinality at the Edge
Federating every raw metric from every leaf server defeats the purpose of scaling. If a leaf server monitors 500,000 active time series and federates all of them to a global server, the global server inherits the exact same cardinality and memory pressure that the architecture was designed to avoid.
To prevent performance degradation, engineering teams use two primary strategies before metrics cross the federation boundary: recording rules and explicit metric selection.
1. Pre-Aggregation via Recording Rules
Instead of sending raw counters and high-cardinality histograms up to the global server, leaf servers should evaluate recording rules to pre-calculate rates, aggregations, and summaries.
For example, instead of federating every raw HTTP request counter across thousands of pods, a leaf server can evaluate a recording rule:
groups: - name: api_aggregations rules: - record: job:http_requests_total:rate5m expr: sum(rate(http_requests_total[5m])) by (job, route)
The global server then federates only the resulting time series (job:http_requests_total:rate5m), reducing millions of raw samples into a manageable set of aggregated metrics.
2. Strict Matcher Filtering
Global servers should explicitly define what they need using narrow match[] parameters. Avoid wildcard selectors like match[]={__name__=~".*"}. Instead, restrict federation to health indicators, high-level SLA metrics, and pre-computed recording rules.
| Metric Type | Recommended for Federation | Rationale |
|---|---|---|
| Raw High-Cardinality Counters | No | Overwhelms global memory with unnecessary dimensions and user IDs. |
| Pre-Calculated Recording Rules | Yes | Reduces data volume while preserving vital trend and performance data. |
| Alerting State & Health Indicators | Yes | Allows central visibility into cluster outages and node degradations. |
| Raw Histograms / Summaries | Generally No | Extremely high storage footprint; better evaluated locally or via downsampling. |
Operational Challenges and Limitations
While powerful, federation is not a silver bullet for distributed monitoring and introduces distinct operational hurdles that platform engineers must manage.
Memory and CPU Overhead on Leaf Servers
When a global server executes a /federate scrape, it forces the leaf server to scan its local TSDB, filter series matching the parameters, and serialize them into text format. If multiple global servers or scrapers query the /federate endpoint simultaneously with complex regex matchers, it can trigger significant CPU spikes, garbage collection pauses, and memory allocation pressure on the leaf instance.
Loss of Exemplars and Native Histograms
Standard text-based federation formats transmit simple floating-point sample values and timestamps. Historically, advanced features such as exemplars (which link metrics to trace IDs) and native histograms do not translate cleanly across standard text-based /federate scrapers without data loss or significant serialization overhead. Operators relying heavily on trace-to-metric correlation must evaluate alternative distributed architectures.
Network Latency and Timeouts
Because federation relies on synchronous HTTP requests, large payload sizes can lead to request timeouts. If a leaf server takes longer than the global server's scrape_timeout setting to generate and transmit the federated payload, the scrape fails, resulting in missing data points on global dashboards.
Alternatives to Prometheus Federation
As cloud-native observability patterns have matured, several alternatives to traditional federation have emerged to address its scaling limitations:
- Remote Write: Instead of a pull-based hierarchical scrape, Prometheus instances can stream samples asynchronously in real-time to remote storage backends (such as Thanos, Cortex, M3DB, VictoriaMetrics, or Cortex) using the Prometheus remote write protocol. This eliminates the polling overhead of the
/federateendpoint. - Thanos and Cortex: These distributed query and storage engines sit on top of Prometheus instances, providing a global view of metrics without requiring manual rule cascading or heavy
/federatescraping configurations. They query leaf instances directly via gRPC or store blocks in object storage.
Frequently Asked Questions
Does Prometheus federation support high availability?
Yes. You can run two identical leaf Prometheus servers scraping the same targets independently, and configure a global Prometheus server to federate from both. By using rules or query-time deduplication, the global layer can handle redundant data streams seamlessly.
How does federation impact network bandwidth?
Federation bandwidth usage depends entirely on the number of time series returned by the match[] parameters and the scrape interval. Using strict filtering and pre-aggregation rules significantly reduces bandwidth compared to scraping raw targets.
Can a global Prometheus server federate from another global server?
Yes. Federation is recursive. You can build multi-tiered hierarchies (e.g., Edge Prometheus $\rightarrow$ Regional Prometheus $\rightarrow$ Global Prometheus), though each additional layer introduces latency and potential points of failure.
Why are my federated metrics showing _exported prefixes?
This happens because the global server's honor_labels parameter is set to false (the default). The global server renames conflicting label names to prevent collision with its own target labels. Set honor_labels: true in your global scrape configuration to retain original labels.
What is the difference between Prometheus remote write and federation?
Federation is a pull-based mechanism where a parent Prometheus server scrapes a child server's HTTP /federate endpoint. Remote write is a push-based mechanism where a Prometheus server actively streams its scraped samples to a remote database or distributed metrics backend in real time.
Conclusion and Next Actions
Prometheus federation provides a native, straightforward mechanism for scaling monitoring architectures horizontally across organizational boundaries and isolated networks. By deploying local leaf servers for high-frequency scraping and central global servers that pull pre-aggregated metrics via the /federate endpoint, engineering teams can maintain deep visibility into complex infrastructure without overloading single instances.
To implement or optimize federation in your environment, start by auditing your current metric cardinality, establishing strict recording rules for high-volume counters, and configuring your global servers with precise match[] parameters and honor_labels: true. For massive, planet-scale deployments exceeding millions of active series, evaluate whether transitioning from pull-based federation to asynchronous remote write architectures or distributed storage engines like Thanos or Cortex better aligns with your long-term observability strategy.