LabHub

Blog

Prometheus in Production: TSDB, Cardinality, Recording Rules, Federation, and Remote Write

한국어English日本語

Prometheus in Production

Introduction

Prometheus is easy to install and much harder to operate well. Many teams begin with a few exporters and dashboards, then run into the same production problems:

Prometheus operations are not about collecting as many metrics as possible. They are about deciding which metrics deserve retention, which labels are safe, which queries should be precomputed, and which storage model fits the real operating need.

TSDB operations: retention is a cost policy

Prometheus’s built-in TSDB is operationally simple, but it makes retention design critical. If retention is vague, the system eventually pays through disk pressure, longer restart times, and harder incident recovery.

The first two questions should always be:

In many production environments, local Prometheus is best treated as a short-retention, high-performance operational store, while long-term history moves elsewhere.

storage:
  tsdb:
    retention.time: 15d

Operational checks should include:

TSDB disk pressure is often not just a storage problem. It is a signal that the metric set or label model is already too expensive.

Cardinality is a design quality issue

Why high cardinality breaks systems

In Prometheus, the cost of a metric is driven by all label combinations. Labels such as user_id, session_id, and request_id create unbounded series growth and are rarely appropriate for general-purpose metrics.

As cardinality rises, several things degrade at once:

Practical operating rules

One of the highest-leverage cost optimizations in Prometheus is not scaling hardware. It is removing labels that do not create operational value.

Recording rules and alerting rules should be designed separately

Recording rules reduce repeated query cost

If dashboards and alerts repeatedly run the same heavy query, the cost multiplies across users and evaluation loops. Recording rules let you precompute the expensive part once.

groups:
  - name: service-latency
    interval: 30s
    rules:
      - record: job:http_request_duration_seconds:rate5m
        expr: sum by (job) (rate(http_request_duration_seconds_count[5m]))

Recording rules are especially useful when:

Alerting rules should reflect operating intent

Good alerts are not defined by complex PromQL. They are defined by clear meaning, stable duration, and a response path.

groups:
  - name: service-alerts
    rules:
      - alert: HighErrorRate
        expr: sum(rate(http_requests_total{status=~"5.."}[5m])) by (job)
          / sum(rate(http_requests_total[5m])) by (job) > 0.05
        for: 10m

Good alert rules typically include:

Without these guardrails, teams often create alerts that are technically correct but operationally noisy.

Federation and remote write solve different problems

When federation fits

Federation is useful when an upper-level Prometheus only needs selected aggregated metrics from lower-level Prometheus servers.

It fits well when:

When remote write fits

Remote write is the better fit when the goal is external retention or centralized queryability.

It fits well when:

These patterns are often mentioned together, but they are not interchangeable. Federation is mainly about hierarchical scraping of selected data. Remote write is mainly about external storage and scale.

What teams should document

Prometheus is not just a binary with a config file. It is an operating system for metric economics. Teams should explicitly document:

1. Metric onboarding policy

2. Rule ownership

3. Storage policy

4. Prometheus SLOs

A practical operations checklist

The most useful recurring checks are:

  1. Is scrape failure rate rising
  2. Did time-series count jump after a recent deployment
  3. Which dashboards and alerts run the most expensive queries
  4. Can those queries be replaced by recording rules
  5. Is local retention increasing restart time or disk pressure
  6. Are federation and remote write being used for clearly different purposes

Prometheus becomes easier to scale when teams treat it as a controlled metric economy instead of an unlimited telemetry bucket.

Closing thoughts

Good Prometheus operations are built on four habits:

Well-operated Prometheus does not mean collecting more metrics. It means keeping better metrics at lower cost with clearer operating intent.

References

Comments

No comments yet.

Sign in to leave a comment