TExcelTAD
Home › Observability: Prometheus, Grafana, Loki & OpenTelemetry › Prometheus at Scale: HA, Remote Write, Thanos & Mimir

Prometheus at Scale: HA, Remote Write, Thanos & Mimir

One Prometheus server on local disk handles a surprising amount: a few million active series and weeks of retention on a single machine. You outgrow it for three reasons: availability (it's a single process), retention (months or years of history), and a global view (many clusters, one query).

High availability: two identical servers

The Prometheus answer to HA is simple: run two identical servers scraping the same targets with the same rules. Each sends its alerts to all Alertmanager replicas, which deduplicate them. Give each server an external_labels replica label:

yaml
global:
  external_labels:
    cluster: prod-eu-1
    __replica__: prom-0          # prom-1 on the other server; long-term stores dedupe on it

The two copies differ slightly (scrapes happen at different moments), so dashboards query one of them or a deduplicating layer in front.

Federation (and why it's rarely the answer now)

A "global" Prometheus can scrape selected series from others through /federate:

yaml
scrape_configs:
  - job_name: federate
    honor_labels: true
    metrics_path: /federate
    params:
      'match[]': ['{__name__=~"job:.*"}']     # only recorded aggregates
    static_configs:
      - targets: ["prom-eu-1:9090", "prom-us-1:9090"]

It works for a handful of aggregated series, but it's fragile at scale (big scrapes, timing gaps). Remote write has mostly replaced it.

Remote write

remote_write streams every sample (or a filtered subset) to a long-term store as it is ingested, buffered by the WAL so short outages of the receiver lose nothing:

bash · try it yourself
cat > prometheus.yml <<'YML'
global:
  scrape_interval: 30s
  external_labels: {cluster: prod-eu-1, __replica__: prom-0}
scrape_configs:
  - job_name: linkly
    static_configs: [{targets: ["linkly:8080"]}]
remote_write:
  - url: https://mimir.example.com/api/v1/push
    basic_auth:
      username: prod-eu-1
      password_file: /etc/prometheus/secrets/mimir-password
    queue_config:
      max_samples_per_send: 2000
      capacity: 10000
    write_relabel_configs:        # ship aggregates and a few raw metrics only
      - source_labels: [__name__]
        regex: 'job:.*|up|linkly_.*'
        action: keep
YML
promtool check config prometheus.yml
Checking prometheus.yml
 SUCCESS: prometheus.yml is valid prometheus config file syntax

Monitor the sender: prometheus_remote_storage_samples_pending, prometheus_remote_storage_samples_failed_total and the gap between prometheus_remote_storage_highest_timestamp_in_seconds and prometheus_remote_storage_queue_highest_sent_timestamp_seconds (how far behind the queue is).

Agent mode (prometheus --agent) is Prometheus with only scraping and remote write: no local queries, no rules, a tiny WAL. It's the right shape for "collect in each cluster, store centrally". Grafana Alloy and the OpenTelemetry Collector can play the same role.

Long-term stores

System Model Notes
Thanos sidecar next to each Prometheus uploads its 2 h blocks to object storage (S3, GCS); Querier fans out and deduplicates; Compactor downsamples; Ruler for global rules keeps Prometheus as is; cheap storage; also has a remote-write Receiver
Grafana Mimir horizontally scalable remote-write backend on object storage, multi-tenant the engine behind Grafana Cloud Metrics; also ingests OTLP
VictoriaMetrics single binary or cluster; remote write, its own PromQL dialect (MetricsQL) very resource-efficient
Cortex Mimir's predecessor CNCF project, still maintained
managed Amazon Managed Service for Prometheus, Google Cloud Managed Service for Prometheus, Azure Monitor managed Prometheus, Grafana Cloud remote write + PromQL API; billed per sample or series (check current pricing)

All of them speak PromQL, so dashboards and alerts move over with a data source change. What changes: per-tenant limits (series, ingestion rate), query performance on long ranges (downsampling), and cost.

A Thanos layout, as a sample:

text
cluster eu-1:  Prometheus ×2 + thanos-sidecar ──upload blocks──▶ ┐
cluster us-1:  Prometheus ×2 + thanos-sidecar ──upload blocks──▶ ├─ S3 bucket ◀── thanos-compactor (downsample 5m, 1h)
                                                                 ┘      ▲
Grafana ──▶ thanos-query ──▶ sidecars (recent data) + thanos-store (bucket) ┘   (deduplicates on __replica__)

Sizing rules of thumb

  • Memory scales with active series (and churn): plan a few KB per series, so 2 million series ≈ several GB of RAM for the head, plus query headroom.
  • Disk ≈ samples/s × bytes per sample (≈1–2) × retention seconds. 100k samples/s for 15 days ≈ 100,000 × 1.5 × 1,296,000 ≈ 195 GB.
  • Watch Prometheus itself: prometheus_tsdb_head_series, rate(prometheus_tsdb_head_samples_appended_total[5m]), prometheus_engine_query_duration_seconds, rule group durations. kube-prometheus-stack includes dashboards for them.

Before scaling out, scale down: drop unused metrics with metric_relabel_configs, cut label cardinality, raise the scrape interval for slow-moving targets (60 s for node metrics is fine). Most "Prometheus is too big" problems are cardinality problems (Labels & Cardinality).

Test yourself

How do you make Prometheus highly available?

  1. A Prometheus cluster with leader election
  2. Two identical servers scraping the same targets, both sending alerts to all Alertmanagers, which deduplicate
  3. One server behind a load balancer
  4. Federation

What is Prometheus agent mode?

  1. A mode for exporters
  2. Scraping and remote write only, without local querying or rules
  3. A Grafana plugin
  4. A debugging mode

What does a Thanos sidecar do?

  1. Scrapes targets
  2. Uploads Prometheus's TSDB blocks to object storage and serves recent data to the Thanos querier
  3. Sends alerts
  4. Replaces Alertmanager