Course map

Topic 078 / Advanced

Time-series databases

Chapter 5.6 · Operational Storage and the Data Lifecycle

What and why

Some workloads are almost entirely append-only, timestamped, and queried by time range — metrics, sensor readings, event logs. A general-purpose table can store this, but a time-series database is shaped specifically for it: cheap range deletion by age, built-in downsampling, and storage that doesn't grow unbounded forever. Builds on: → 61 (NoSQL databases).

Diagram

Workload trait General table Time-series engine
Append-heavy, rarely updated fine fine
Range-scanned by time needs a timestamp index native, partitioned by time
Expired by age row-by-row DELETE drop a whole time partition
Needs downsampling hand-rolled rollup jobs built in

How it works

  1. Recognize the workload shape: mostly inserts, each row timestamped, queries almost always filter or aggregate by time range.
  2. A time-series store partitions data by time internally, so old data can be dropped or downsampled cheaply — a whole partition removed in one metadata operation instead of deleting rows one by one.
  3. Downsampling: keep raw resolution briefly, then roll up into coarser aggregates (per-minute, then per-hour) as data ages, bounding storage growth.
  4. A plain relational table holding the same data pays for both: deleting old rows is a slow row-by-row operation that still touches every index, and there's no free downsampling.

Practical example

(illustrative). A metrics system ingesting 10,000 points/sec drops a day-old partition in one metadata operation in a time-series engine, where a plain indexed table would run a DELETE … WHERE ts < ? touching the index on every one of millions of rows.

When to use it

  • Use when: monitoring/metrics, IoT sensor streams, or any workload that is overwhelmingly append-and-range-query-by-time at real scale.
  • Avoid when: the query pattern isn't actually time-dominant, or volume is small enough that a plain indexed table with a scheduled cleanup job is fine.
  • Failure scenarios: retention implemented as row-by-row DELETE on a huge table, causing index bloat and long-running transactions that block other work.
  • Simpler alternative: an ordinary table with a timestamp index and a scheduled batch job to delete or archive old rows, until volume actually justifies a dedicated engine.

Practice

(15–20 min, lab Postgres). Create a plain table with a timestamp column and index, insert a batch of time-stamped rows, then use EXPLAIN to compare the cost of DELETE … WHERE ts < ? against what dropping a pre-partitioned chunk would cost conceptually in a dedicated time-series engine. Done when you can state, in one sentence, why the partition-drop is cheaper.

Shared lab setup

Key takeaway

A time-series database isn't a different query language — it's the same range-by-time workload with retention and downsampling built in instead of hand-rolled. Done when you can: name the two operations (retention, downsampling) a general table has to build by hand. Used next in → Project 19; metrics storage → 201.

References

None — this topic makes no external claims.

Source directory

Search the guide