Learn Labs
Scaling & High Availability

Long-Term Storage

Thanos, Mimir, VictoriaMetrics, and global views

Plain Prometheus keeps weeks of data on one local disk. Eventually you'll want things it can't give you: a year of history for capacity planning, one query across twenty clusters, and storage that survives losing a machine. Three open-source projects dominate this space. They all speak PromQL, so Grafana and your queries barely change.

The shared idea

All of them separate the jobs Prometheus does on one machine:

  • Ingest: Prometheus keeps scraping, or runs as an agent.
  • Store: blocks go to object storage (S3, GCS, Azure Blob, SeaweedFS), which is cheap, durable, and effectively unlimited.
  • Query: a stateless query layer fans out across recent data and object storage, deduplicates HA pairs, and merges the results.
  • Compact and downsample: background jobs merge blocks and create 5-minute and 1-hour resolution copies for fast long-range queries.

Thanos

Thanos bolts onto existing Prometheus servers.

ComponentJob
SidecarRuns next to each Prometheus; uploads finished blocks to object storage and serves recent data to queries
Store GatewayServes historical blocks from object storage
QuerierFans out PromQL to sidecars and stores, deduplicates replicas by the replica label
CompactorCompacts and downsamples blocks in the bucket; applies retention
RulerEvaluates rules against the global view
ReceiveOptional remote-write ingestion instead of sidecars

Its strength is incrementalism: keep every Prometheus as it is, add a sidecar, and you get a global query view and unlimited retention.

Grafana Mimir

Mimir (descended from Cortex) is a horizontally scalable, multi-tenant remote-write backend. Prometheus servers, or agents, remote_write into it; it shards series across ingesters, replicates them 3x, and flushes blocks to object storage.

  • Built for very large scale (hundreds of millions of series) and many tenants with per-tenant limits.
  • Runs as microservices or a single "monolithic" binary for smaller setups.
  • Includes a ruler and Alertmanager, so alerting can be centralized too.

VictoriaMetrics

A separate implementation of a Prometheus-compatible TSDB, known for low resource usage and operational simplicity. Single-node mode is one binary that accepts remote write (and many other protocols) and can replace Prometheus storage entirely; cluster mode splits insert, select, and storage. Its query language, MetricsQL, is a PromQL superset with a few semantic differences (for example, in how rate() handles window edges), worth knowing before porting alerts.

Choosing

If you...Consider
Have a few Prometheus servers and want history and a global view with minimal changeThanos with sidecars
Need a central multi-tenant platform for many teams, at large scaleMimir
Want the simplest, cheapest single-node long-term storeVictoriaMetrics single-node
Don't want to operate any of itA managed service (Grafana Cloud, Amazon/Google/Azure managed Prometheus)
Have one cluster and 30 days is enoughNothing. Plain Prometheus.

Downsampling, honestly

Long-term stores keep 5-minute and 1-hour downsampled data so a one-year graph doesn't load billions of raw samples. Two consequences:

  • You can't see short spikes in old data. A 30-second outage last March is invisible in 1-hour resolution.
  • Downsampled data stores aggregates (min, max, sum, count, counter) per interval, so rate() still works on it, but the window must be at least a few times the resolution. rate(x[5m]) on 1-hour data returns nothing.

A sketch with this repo

The repo's SeaweedFS module provides an S3-compatible object store, so a natural extension is a Thanos sidecar next to the prometheus service, writing blocks to a SeaweedFS bucket:

thanos-sidecar:
image: quay.io/thanos/thanos:<version>
command:
  - sidecar
  - --tsdb.path=/prometheus
  - --prometheus.url=http://prometheus:9090
  - --objstore.config-file=/etc/thanos/bucket.yml   # type: S3, endpoint: host.docker.internal:8333
volumes:
  - prometheus_data:/prometheus     # shares the TSDB volume

plus a querier and store gateway. Prometheus needs --storage.tsdb.min-block-duration=2h and --storage.tsdb.max-block-duration=2h so it never compacts blocks itself, because the Thanos compactor does that in the bucket. That's a good capstone extension, now that the SeaweedFS module exists.

On this page