Course contentsShow
← System Design
Lesson 1269 of 1,91932. Monitoring and AlertingFree lesson

Time Series Databases for Metrics

Learning how TSDBs optimize storage and queries for timestamped numeric data with tags, dimensions, and high cardinality.

Time Series Databases for Metrics

You'll learn how specialized time-series databases optimize storage and querying for metric data by exploiting its unique characteristics.


What Makes Metrics Data Special?

Metrics are fundamentally timestamped numeric values with associated labels (tags). Every data point follows the pattern: (timestamp, value, {dimension1=x, dimension2=y}). Unlike general-purpose databases handling varied data types and query patterns, metrics have predictable structure: continuous time-ordered writes, mostly sequential reads, and aggregation-heavy queries.

How TSDBs Optimize Storage

Time Series Databases (TSDBs) like Prometheus, InfluxDB, and Graphite exploit these patterns:

Compression: Since consecutive values are often similar, TSDBs use delta encoding (storing differences) and specialized compression algorithms. A CPU metric going 50.1%, 50.3%, 50.2% stores more efficiently as base value + tiny deltas.

Columnar layouts: Values, timestamps, and tags are stored separately. When you query "average CPU over 5 minutes," the TSDB reads only the values column, not the entire row structure.

Chunking: Data is organized into time-based blocks (e.g., 2-hour chunks). Old blocks become immutable and highly compressible. Recent data stays in memory for fast writes.

Handling High Cardinality

Cardinality is the number of unique label combinations. {service="api", region="us-east", pod="xyz"} creates distinct time series. TSDBs use inverted indexes (tags → series IDs) and carefully manage memory because each unique series costs RAM for indexing.

Query Optimization

TSDBs pre-aggregate data at write time and support time-range filtering natively. They're built for queries like "95th percentile latency over the last hour grouped by region"—exactly what monitoring needs.

Key Takeaway: Time Series Databases dramatically outperform general databases for metrics by compressing timestamped data, organizing by time blocks, indexing high-dimensional tags, and optimizing for range queries and aggregations.