Skip to main content
← CONCEPTS / TIME-SERIES DATABASES
An end-to-end domain learning journey

Gorilla Time-Series Compression: Delta-of-Delta
& XOR Floats.

Gorilla encodes regular-interval timestamps in 1 bit via Delta-of-Delta and compresses slowly changing IEEE-754 floats via XOR bit-windows, shrinking 16-byte samples to ~1.37 bytes.
Start the journey5 sections· Last modified Nov 26, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When building an in-memory TSDB buffer, use Gorilla Delta-of-Delta + XOR per 2-hour chunk for O(1) streaming writes and ~11x lossless compression.

TL;DR30-second simplified summary
▾

Delta-of-Delta collapses regular scrapes to 1 bit, while XOR window reuse keeps slowly changing float64 values compact inside 2-hour chunks.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
IEEE-754 64-Bit Floating Point Layout
Know that a float64 packs 1 sign bit, 11 exponent bits, and 52 mantissa bits—and nearby values share almost identical upper bits.
Bit-Level Streaming Buffers
Understand writing variable-width bitfields (1 bit, 7 bits, 9 bits) rather than byte-aligned integers.
Full walkthrough · 5 stages
01
L4 · FUNDAMENTALS

P · Problem & Why Uncompressed Telemetry Blows Up RAM.

Every raw metric sample is 8 bytes for the Unix timestamp + 8 bytes for the float64 value = 16 bytes.

At 10M samples/sec, 2 hours (7,200 seconds) of hot operational metrics equals 72 billion points = 1.152 TB of raw DRAM before any index overhead. Compressing with gzip/Zstd across 10M separate series buffers either forces tiny 100-byte blocks (poor ratio) or delays flushing until buffers fill.

Memory Efficiency

Raw 16-Byte Samples vs. Gorilla 1.37-Byte Bitstream

Before · Uncompressed (int64 + float64)
  • 16 bytes per data point
  • 1.15 TB DRAM for 2h @ 10M/s
  • No bit-level redundancy removal
After · Gorilla Bit-Stream
  • ~1.37 bytes/point (~11.6x)
  • ~98 GB DRAM for same 2h window
  • O(1) streaming append & read
02
L4 · FUNDAMENTALS

R · Representation: Delta-of-Delta Timestamp Encoding.

Suppose a Prometheus scraper polls a node every 60 seconds: t0=0, t1=60, t2=120, t3=181.

The first differences are 60, 60, 61. The second differences (Delta-of-Delta D) are D2 = 60 - 60 = 0 and D3 = 61 - 60 = +1. Gorilla uses a variable-length prefix code: '0' (1 bit) for D == 0; '10' + 7-bit signed D for [-63, 64]; '110' + 9-bit D for [-255, 256]; '1110' + 12-bit D for [-2047, 2048]; and '1111' + 32-bit D otherwise.

Delta-of-Delta Pipeline

t_n -> First Delta -> Delta-of-Delta -> Variable Bit Bucket

Incoming t_nDelta (t_n -t_{n-1})Delta-of-Delta DBitstream Out1. Compute step interval2. Subtract previous interval3. D=0 -> emit single '0' bit4. D!=0 -> 7/9/12/32-bit bucket
03
L5 · APPLIED DESIGN

I · Invariant: IEEE-754 XOR Floating-Point Compression.

Subtracting two float64 numbers (42.3 - 42.1) creates floating-point rounding noise across all 52 mantissa bits. Bitwise XOR (v_{n-1} ^ v_n) preserves exact lossless bit equality.

Gorilla computes xor = prev_bits ^ curr_bits. Case 1: xor == 0 -> emit '0' (1 bit). Case 2: xor != 0 -> emit '1'. If the non-zero meaningful bits fall inside the previous XOR's [leading_zeros, trailing_zeros] window, emit '0' + just those meaningful bits! Otherwise emit '1' + 5 bits (leading zeros, capped at 31) + 6 bits (meaningful bit count - 1) + the meaningful bits.

XOR Bit-Window

64-Bit Float XOR -> Zero Check -> Window Reuse vs. New Window

prev_u64 ^ curr_u64ingressxor == 0 -> '0' (1bit)computeFits Window ->'10'+bitsstorageNew Window ->'11'+5b+6bcontrolidenticallead/trail >= prevwider span
04
L5 · APPLIED DESIGN

M · Mechanics at Scale: 2-Hour Blocks & Random-Access Limits.

Gorilla encoding is stateful and sequential: to decode point #500, you must decode points #1 through #499 from the start of the chunk.

Resetting chunks every 2 hours (e.g., 120 points at 60s scrape, or 720 points at 10s scrape) bounds decode latency to microseconds and caps blast radius if a chunk is evicted or corrupted. It also aligns cleanly with Prometheus/VictoriaMetrics block compaction.

2-Hour Chunk Lifecycle

Open Chunk (Append Bits) -> 2h Seal -> Flush to Block Store

t >= block_endasync WAL truncateActive 2h ChunkSealed ImmutableCompacted toDisk/S3
Engineering Decision Framework
Problem
How to store billions of streaming metric points in RAM with ~10x compression and sub-millisecond reads.
Naive Solution
Store raw 16-byte structs or run Zstd on every incoming point.
Why It Fails
Raw structs blow up DRAM by 11x; Zstd requires batching or burns CPU re-compressing tiny per-series buffers.
Alternatives
Raw arrays vs. Zstd batches vs. Gorilla Delta-of-Delta + XOR 2-hour chunks.
Engineering Decision
Use Gorilla streaming bit-compression per 2-hour chunk in RAM, then optionally apply Zstd/Parquet when flushing cold blocks to S3.
Trade-Offs
Sequential decode within a 2-hour chunk (mitigated by capping chunk duration at 2h) in exchange for O(1) append and ~1.37 B/point.
05
L6 · SCALE & TRADE-OFFS

E · Edge Cases, Assumptions & When NOT to Use Gorilla.

Gorilla assumes timestamps per series arrive mostly in order at regular intervals and values change smoothly.

When NOT to use Gorilla: (1) High-entropy random floats or cryptographic hashes—XOR windows stay near 64 bits wide, making Gorilla larger than 16 bytes due to control bits! (2) Heavy out-of-order writes—an append-only bitstream cannot insert t_n < t_{n-1} mid-chunk without rewriting or using an out-of-order buffer.

Workload Fit

Smooth Gauges (1.37 B/pt) vs. Out-of-Order / Random Entropy

CPU / Mem Gauges~11x Gorilla WinOut-of-Order SpikesNeeds OOO BufferRandom / EncryptedUse Raw / Zstd
Decision Exercise · Make the Call

A team uses Gorilla XOR compression on a time series of uniformly random 64-bit UUID hashes cast to floats. Compression ratio drops to 0.96x (worse than uncompressed!). Why?

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

In Gorilla timestamp compression, how many bits are needed to encode a timestamp whose Delta-of-Delta `D` equals `0`?

Recommended Learning Flow