DEV Community

Cover image for Thanos Prometheus high availability and long-term storage
Span Observer
Span Observer

Posted on Originally published at span.observer

Thanos Prometheus high availability and long-term storage

Your single Prometheus keeps fifteen days of data, and the incident review asks: « what about last month? » Or the machine restarts mid-outage and your graphs have a hole. A Thanos Prometheus high availability setup answers both: several replicas that cover for each other, and object storage for history.

The facts here come from the thanos-io/thanos repository and the official documentation, read on 12 November 2026. I did not deploy the stack to write this: the commands are the documented ones, and the retention values in the example are mine, to adapt.

If you would rather have a central backend than a layer above your Prometheus servers, compare with Grafana Mimir. For rules, see naming recording rules. To place Prometheus next to OpenTelemetry, read OpenTelemetry and Prometheus, complementary tools.

The operations problem: one Prometheus is a single point

Prometheus stores data on its local disk. That is simple and reliable, but it raises three questions.

  • Availability: if the instance dies, collection and alerting stop. Running two identical copies fixes that, but dashboards then show duplicate series.
  • Duration: months of data on a local disk is costly and slows queries.
  • Global view: with one Prometheus per cluster, no query crosses all clusters.

The repository describes Thanos as a « highly available Prometheus setup with long term storage capabilities ». It is licensed Apache 2.0, shows about 14,300 stars and CNCF incubating status. The documentation mentions a minor release every six weeks: check the releases page rather than copying a number from here.

Thanos Prometheus high availability: the idea in one sentence

You keep your Prometheus servers. Thanos adds independent components around them, all speaking the same gRPC interface, the Store API. A query component asks every source at once and returns one result. Each piece is replaceable, and you install only what you need.

Component Role When to add it
Sidecar Exposes a Prometheus’s data and ships its blocks to object storage From the first Prometheus
Receive Accepts remote write and stores locally If you can only push
Query Queries all sources with PromQL, deduplicates Always
Store Serves history from object storage When you want more than local disk
Compact Compacts, downsamples, applies retention As soon as the bucket fills

Step 1: a sidecar next to each Prometheus

The sidecar runs beside a Prometheus instance. It serves its data to queries through the Store API and, if configured, uploads its blocks to object storage. The documentation sets a few conditions worth checking one by one.

  1. Each Prometheus’s external_labels must be unique across the whole Thanos system.
  2. The admin API must be on (--web.enable-admin-api), because the sidecar reads external labels from it.
  3. Min and max block durations must be equal; the documentation recommends 2h, to avoid corrupting uploaded data.
  4. Keep local retention at three times the block duration or more, so at least 6 hours, to survive an object storage outage.

The sidecar uploads only uncompacted blocks, produced every two hours. The latest two hours are therefore read straight from Prometheus.

Commands from the Thanos documentation: starting Prometheus with 2h blocks, then the sidecar with tsdb.path, prometheus.url and objstore.config-file

Step 2: Query and replica deduplication

Query implements the Prometheus HTTP v1 API, so your dashboards and PromQL do not change. It is stateless and scales out easily.

High availability rests on one detail: each replica carries an external label that tells it apart, such as replica="a" and replica="b". With --query.replica-label replica, Query treats series that differ only by that label as one. The documentation gives a telling example: the same query on up returns 2 results with the flag and 3 without.

The thanos query command from the documentation, with http-address, query.replica-label replica and two endpoint options pointing to Store APIs

Decide one thing in advance: what happens when a source does not answer? Partial response is on by default with the « abort » strategy, so the query fails. The « warn » strategy returns what it has, with a warning. On call, choose explicitly.

Step 3: history with Store and the compactor

The Store Gateway serves object storage data. It keeps a small index per block locally, in the --data-dir folder; deleting it loses nothing, it will be rebuilt. The index cache is in memory by default (250MB), with Memcached or Redis as options. The --min-time and --max-time flags let you split history across several Store instances.

The compactor is a singleton: the documentation says only one instance may work on a single stream of blocks in one bucket. It compacts, downsamples (5 minutes after 40 hours, 1 hour after 10 days) and applies retention with --retention.resolution-raw, -5m and -1h. The default is 0d: keep everything, forever.

Two traps. First, downsampling adds blocks rather than replacing them: plan for roughly three times the space if you keep every resolution. Second, retention runs after compaction: if that fails, nothing is ever deleted.

thanos compact commands with the three retention.resolution options (example values 30d, 90d and 365d), then thanos store with data-dir and objstore.config-file

Sidecar or Receive: the decision

The sidecar assumes you can install a component beside each Prometheus and that Query can reach it. When that is not possible, Receive steps in: Prometheus pushes remote write to /api/v1/receive, Receive writes it to a local TSDB, uploads to object storage and exposes it to Query. The documentation recommends it for environments where you can only push, such as no inbound access.

Receive adds settings to understand: --receive.replication-factor (1 by default), hashrings, and a write quorum of int(RF/2)+1, with a special case for RF=2. For new installs, the documentation recommends the Ketama algorithm over hashmod. I have not tested these under load.

How to check that it works

  1. Query a simple metric (up) in Query with deduplication on, then off: the series count must change.
  2. Stop one Prometheus replica: the same query must still answer, with the other replica’s series.
  3. Look at the bucket: new blocks should appear every two hours.
  4. Query a period older than your local retention: the answer comes from Store.

Best practices

  • One compactor per bucket, and an alert if it stops.
  • Unique external labels, and a replica label shared by the pair.
  • Retention written from a need (post-mortem, audit), not a round number.
  • Do not start with every component: sidecar, Query, Store and compactor are often enough.

Frequently asked questions

Does Thanos replace Prometheus?

No. Prometheus still collects and evaluates rules. Thanos adds global queries, deduplication and long-term storage.

Thanos or Mimir?

Thanos starts from your existing Prometheus servers and federates them. Mimir is a central store that receives remote write. Both use object storage; compare on the operations burden you want to carry.

What does Dynatrace say about this?

This article covers third-party open source tools only. For Prometheus metrics on the Dynatrace side, consult docs.dynatrace.com, keeping SaaS and Managed apart.

Conclusion

Start with the sidecar and Query for high availability, add Store and the compactor when history matters, and keep Receive for cases where you can only push. Sources: Thanos getting started, thanos-io/thanos repository.

span.observer is an independent community blog, not affiliated with Dynatrace LLC or the Thanos project. Brands mentioned belong to their owners. Tools change quickly: check commands and options against the official documentation.


Originally published on span.observer. French version: https://span.observer/fr/thanos-prometheus-haute-disponibilite/.

Top comments (0)