LOAD-BEARINGfree
FoundationsTier 3 · unit 10 of 12 · 13 min read

Time-series and append-heavy data

Metrics, clickstream, IoT readings, audit events, financial ticks. They look like ordinary rows and they behave nothing like them, which is why a schema that works beautifully for orders will fall over inside a month when you point it at events.

The shape: writes are appends, they carry a timestamp, they arrive roughly in time order and at a rate that dwarfs your business tables, they are never updated, reads are almost always a range over recent time plus an aggregate, and the value of a row decays — today's data is queried constantly, last April's is queried once a quarter. Almost every instinct in this tier was formed on data with the opposite shape.

Three instincts to unlearn

  • You are not looking rows up by identity. You want ranges and aggregates, so a B-tree secondary index on a high-cardinality column over two billion rows is a scan with extra steps — one that also has to be maintained on every single insert.
  • Your write pattern is sequential, so use an engine that likes that. Lesson 3.01's LSM tree turns appends into sequential writes, which is exactly the workload. A B-tree with a monotonically increasing key concentrates every insert on the rightmost page, and that page becomes the contention point.
  • Deleting old data is not a DELETE. Removing forty million expired rows is the most expensive statement your database will run this week, competing with production traffic and leaving bloat behind.

Partition by time, and most problems dissolve

The single decision that matters. Store the data in chunks — one per day, or hour, sized so a chunk's working set fits comfortably in memory. Four things fall out at once. A query for last week prunes to seven partitions and never touches the other three years. Expiry becomes DROP PARTITION: instant, no bloat, no impact — which is the mechanism Lesson 3.07 promised when it said retention is part of the design. Each partition carries its own small indexes rather than one enormous one. And older partitions can be compressed or moved to cheaper storage independently, because nothing will ever write to them again.

Cardinality is what actually kills you

A time series is identified by its name plus its full set of labels, and the number of distinct series is the multiplier on everything — index entries, in-memory state, memory at query time. A metric with 4 endpoints × 5 status codes × 10 hosts is 200 series, and it costs nothing.

Then someone adds user_id as a label, because it would be useful during debugging. Two hundred series becomes two million, and the ingestion tier falls over. This is the most common operational failure in metrics systems anywhere, it is caused by one innocuous line in application code, and it passes review because nothing about the line looks expensive. The rule worth stating in your own team: labels are for dimensions you group by, never for identifiers. High-cardinality identity belongs in logs or traces, which are indexed for lookup rather than aggregation.

Rollups, and the aggregate you cannot un-average

Because value decays with age, the standard shape is a resolution ladder maintained by a background job: raw for seven days, one-minute aggregates for thirty, one-hour for two years. Storage drops by orders of magnitude and the dashboard querying last quarter reads thousands of rows instead of billions.

One trap inside this is worth memorising, because it produces charts that are confidently wrong. Averages do not compose, and neither do percentiles. The mean of twelve five-minute means is only the hourly mean if every bucket had identical counts — so store sums and counts and divide at read time. Percentiles are worse: a p99 genuinely cannot be recovered from stored p99s, at all. If you want percentiles over arbitrary ranges, the rollup must retain a mergeable structure — a histogram with fixed buckets, or a sketch like t-digest — and not a single number.

Late data, and the compression payoff

A device offline for three hours delivers 6am's readings at 9am, and a write into an old partition may be expensive, already compressed, or outside your retention window entirely. That is not an edge case, it is normal, and it is why event time and processing time are different quantities. Lesson 7.03 develops this properly with watermarks and late-data policy; the storage-layer half is simply that your partitioning scheme has to accept a bounded amount of backfill.

The compensation is compression. Values from one series in time order are extraordinarily predictable: timestamps at a fixed interval delta-encode to almost nothing, and consecutive floats compress hard because their bit patterns barely differ. Ten to twenty times reduction is routine for a purpose-built store versus a row store holding the same points — which is the real reason a dedicated engine wins, and also why a plain relational table quietly costs you an order of magnitude in disk.

The trap

Putting the event firehose in your primary OLTP database because it is already there and "it is only an insert". The write volume evicts the pages that serve your users, the retention job competes with live traffic, and the analytical range query over three months holds a snapshot open. You have imported the problem Lesson 7.01 is entirely about, into the one database that must not have it. Partitioned tables in your relational store are a perfectly good answer at modest scale — a dedicated time-series engine earns its place when cardinality or ingest rate outgrows them — but either way this data belongs somewhere its worst query cannot reach a customer.

Going deeper

  • Gorilla: A Fast, Scalable, In-Memory Time Series Database Pelkonen et al., VLDB 2015
    The delta-of-delta timestamp and XOR float encodings that most time-series compression descends from.