Course contentsShow
← Software Engineering
Lesson 1141 of 1,93334. Logging and ObservabilityFree lesson

Time Series Databases

How TSDBs like Prometheus store and efficiently query high-cardinality time-stamped metrics data.

Time Series Databases

You'll learn how time series databases (TSDBs) like Prometheus efficiently store and query the high-cardinality, time-stamped metrics data that power observability systems.

What Makes Time Series Data Special

When you collect metrics—counters, gauges, histograms—every data point has a timestamp and often multiple labels (like service=checkout, environment=prod, region=us-east). This creates time series: sequences of values indexed by time. Traditional databases struggle with this workload because metrics generate massive write volumes and queries typically aggregate across time ranges.

How TSDBs Work

Think of a TSDB like a specialized filing system for metrics. Instead of storing each data point individually, it organizes data by series (unique combinations of metric name and labels). Here's the magic:

Efficient Storage

TSDBs use compression techniques optimized for sequential numeric data. Prometheus, for example, stores data in time-based chunks and uses delta encoding—storing differences between consecutive values rather than absolute numbers. This shrinks storage dramatically.

High-Cardinality Indexing

When you have labels like user_id or container_id, you get high cardinality—millions of unique series. TSDBs build specialized indexes (often inverted indexes) that let you quickly find all series matching environment=prod AND service=checkout without scanning everything.

Time-Range Queries

TSDBs are built for questions like "Show me average CPU for the last hour." They pre-organize data chronologically and can skip irrelevant time blocks entirely, making aggregations blazingly fast.

The Trade-Off

TSDBs sacrifice general-purpose flexibility for speed and efficiency with time-stamped data. You can't do complex joins or transactions, but you can ingest millions of data points per second and query them in milliseconds.

Key Takeaway: Time series databases use specialized storage formats, compression, and indexing to efficiently handle the high-volume, time-stamped, multi-dimensional metrics data that observability systems depend on.