Time-series · Engineering
Choosing per-column codecs
Delta, delta-of-delta, Gorilla XOR, dictionary, bit-packing, and byte-shuffle: how time-series columns get smaller.
A time-series row often has the same shape: a timestamp, a series id, a few numeric measurements, a status string, and maybe a counter or boolean. Storing all of that as JSON repeats field names and text on every sample.
NonoDB’s time-series buckets encode each field as a typed column and choose a codec per column. The encoder tries the applicable codecs, keeps the smallest payload, and only applies the final zlib stage when it actually helps.
Why one codec is not enough
Different columns have different distributions:
- timestamps usually increase by a fixed interval;
- floats change slightly from sample to sample;
- status strings repeat a small set of values;
- counters increase monotonically;
- booleans alternate or stay constant.
A single compression algorithm has to compromise. A per-column choice can use the structure of each field.
The codecs
| Codec | Best for | How it works |
|---|---|---|
| Delta | Monotonic integers and timestamps | Store the difference from the previous value |
| Delta-of-delta | Regular sampling intervals | Store the change in the delta |
| Gorilla XOR | Slowly changing floats | XOR consecutive values and encode leading/trailing zeros |
| Dictionary | Repeated strings | Store unique values plus bit-packed indexes |
| Frame-of-reference bit packing | Bounded integer counters | Store a base plus fixed-width offsets |
| Boolean bit packing | Booleans | One bit per value |
| Byte shuffle + zlib | Numeric columns with patterns | Reorder bytes by significance, then deflate |
The time column uses delta-of-delta with varints. Integer counters can use delta, delta-of-delta, or frame-of-reference bit packing. Floats use Gorilla XOR. Repeated strings use a dictionary plus bit-packed indexes. Booleans use one bit per value.
The final stage is byte shuffle plus zlib per column, only when the compressed payload is at least two bytes smaller. compression controls zlib effort: fast, balanced (default), or max.
Why “try everything” is practical
The encoder has a small set of applicable codecs per column type. It can try them and keep the smallest payload. The cost is CPU during sealing, not during every insert.
Open buckets are uncompressed. When a bucket seals, the encoder does the work once. That keeps the hot append path cheap and moves compression to a bounded background step.
What the column type does not know
The encoder sees values, not semantics. A counter that resets is not a monotonic counter. A float that is mostly constant but occasionally spikes may not compress as well as a smooth signal. A string with high cardinality is a poor dictionary candidate.
That is why the result depends on the data. The same codec can be excellent for one workload and mediocre for another.
A concrete result
On a 50k-row benchmark with 10 series, three floats, one enum string, one counter, one boolean, and a nested meta object:
raw JSON bytes : 9,161,040columnar bytes : 210,374 (4.21 bytes/row, 43.6x smaller)row-oriented zlib : 554,825 (11.10 bytes/row)The columnar path is about 2.64× smaller than whole-row zlib on the same data. The gap grows with low-cardinality columns and regular sampling.
That is a storage result, not a query-latency claim. Compression reduces I/O and footprint; it does not make every query faster.
When compression does not help
- Very short buckets with few rows: overhead can dominate.
- High-cardinality strings: dictionary indexes grow with unique values.
- Random floats: Gorilla XOR has little structure to exploit.
- Already-compressed payloads: zlib will not help.
- Open buckets: they are uncompressed until sealing.
The encoder only accepts zlib when it wins, so a bad final stage is skipped. But the columnar layout itself still has metadata overhead.
Tuning knobs
compression: zlib effort, not the choice of column codecs.bucketMaxDocs/bucketMaxBytes: larger buckets improve compression but increase rewrite cost.granularity: changes bucket windows, which changes how many rows share a bucket.
There is no “set compression to maximum and forget it” answer. Measure the workload, inspect disk usage, and remember that compaction is required to reclaim the high-water mark.
The time-series guide has the full codec table and reproduction commands.