Time-Series Databases

Time-Series Databases (TSDBs) are built to handle sequences of data points indexed in time order. From server telemetry (CPU utilization, memory, latency) to financial market ticks and IoT sensor metrics, time-series data is append-only, high-volume, and time-stamped.

Core Architecture & Optimizations

1. Sequential Append-Only Writes

Traditional relational databases spend CPU/disk resources performing random B-Tree index updates. TSDBs use LSM-Trees or Columnar MergeTrees (e.g. ClickHouse, InfluxDB) that turn random writes into fast sequential disk append operations.

2. Time-Based Partitioning (Hypertables)

Data is automatically sliced into immutable time chunks (e.g. 2-hour or 1-day blocks). Expired data can be purged instantly by dropping the partition block file on disk (DROP PARTITION) rather than executing expensive SQL DELETE queries that cause index bloat.

3. Specialized Compression

  • Delta-of-Delta: Timestamp differences ($\Delta_1 - \Delta_0$) for fixed-interval metrics (e.g., every 10 seconds) compress to 1 bit per sample.
  • Gorilla Float Compression: Compresses 64-bit floating point metric values using XOR bitwise differences down to ~1.37 bytes.
graph TD
    A["Incoming Metric Stream<br/>50,000 writes/sec"] --> B["In-Memory Memtable<br/>Gorilla + Delta-of-Delta Compression"]
    B --> C["Immutable Chunk File<br/>2-Hour Time Partition"]
    C --> D["Background Compaction<br/>Merge & Downsample"]

The High-Cardinality Bottleneck

Cardinality is the number of unique time series generated by tag combinations: Cardinality = Unique Services * Hosts * Endpoints * Status Codes

If application developers accidentally inject dynamic variables like user_id or uuid into metric labels, cardinality explodes into millions of streams, overwhelming inverted indexes in RAM and causing OOM crashes.

Key Takeaways

  • TSDBs handle append-only, time-ordered data with 10–100x better compression than RDBMS.
  • Time-partitioning enables instant retention drops via partition file deletion.
  • Guard against High Cardinality by keeping metric tags strictly limited to low-cardinality enums.

In the next section, we explore Search Engines and Full-Text Search.

Display Options
Appearance
Text Size
100%