LSM-Tree Space-Time Trade-Offs in Key-Value Stores

Leveling, tiering and size ratios decide how much disk your key-value store wastes on stale data. Here is the frame you need before reading the research on better trade-offs.

Binary Buddies · 5 min read · 2 views

An LSM-tree key-value store never updates data in place. Every overwrite and every delete is a new record, and the old versions stay on disk until compaction merges them away. How aggressively the engine compacts decides three costs at once: how much write I/O each insert eventually causes, how many places a lookup has to check, and how much disk is spent on stale data. You cannot drive all three down together. Every merge policy picks a point in that space, whether or not anyone chose it on purpose.

The paper Better Space-Time Trade-Offs for LSM-Tree Based Key-Value Stores (hosted as dostoevsky.pdf) is about that choice. The extract we had to work from was unreadable PDF stream data, so this article does not quote its results, mechanisms or benchmark numbers. For those, read the paper. What follows is the engineering frame you need to read it well: which costs are in tension, which knobs move them, and where tuning them is not worth the effort.

Three costs that pull against each other

Write amplification is the total bytes written to storage divided by the bytes the application wrote. In an LSM-tree, a record is first flushed from memory and then rewritten each time a compaction merges the run it sits in. Merging more often rewrites the same record more times.

Read cost is how many sorted runs a point lookup or range scan has to probe. Merging less often leaves more runs on disk. Filters can help point lookups skip runs, but range scans still have to consult every run that overlaps the range.

Space amplification is disk used divided by the size of the live data. Superseded versions and tombstones count against you until a merge discards them. Merging less often means obsolete entries survive longer and take up more space. An engine that is cheap to write to therefore tends to be either expensive to read from, expensive in disk, or both.

Merge policy decides where the cost lands

The main lever is how runs are merged within and across levels. Two policies sit at the ends of the range. Under leveling, each level keeps a single sorted run, and new data arriving at a level is merged into it straight away. Lookups stay cheap and stale versions are dropped quickly, but each record is rewritten many times as it moves down the tree.

Under tiering, a level collects several runs and merges them only when the level fills. Each record is rewritten fewer times, so writes get cheaper. The price is more runs to probe on reads, and more duplicate and deleted data on disk between merges.

The second lever is the size ratio between adjacent levels. It sets how many levels the tree has for a given data size, and how much work each merge does. Policy and ratio together set the trade-off. Treating them as independent settings is a common way to get a configuration that is worse on every axis than one you could have had.

Why the largest level dominates

With a fixed ratio between levels, capacity grows geometrically, so most of the data lives in the deepest level. That has a direct effect on space. Whatever stale data the last level is allowed to hold accounts for most of the space amplification of the whole tree. The smaller levels above it, however loosely they are managed, are a small fraction of the total by construction.

The same reasoning applies to reads and writes, though the arithmetic differs. Not every level contributes equally to each cost. A policy that is uniform across all levels is a simplification, not a law. That is why a paper titled around better space-time trade-offs is worth reading: the space between pure leveling and pure tiering is larger than the two named policies suggest.

Reading the paper as a practitioner

Go in with specific questions rather than reading it as a general survey. Which cost model does it use for write, point-read, range-read and space, and does that model match your access pattern? Which parameters does it expose, and can your engine actually set them? Storage engines differ in how much of their compaction policy is configurable. If a tuning result needs per-level control that your engine does not offer, it describes a different system.

Also check the workload assumptions behind any comparison: the mix of reads and writes, the share of point lookups versus range scans, key distribution, and update rate. A configuration that wins on an insert-heavy workload with mostly point reads can lose badly once range scans become a large share of traffic. Re-run the comparison on a trace of your own traffic before you change production settings.

Where this does not fit, and what to watch for

  • Small or read-mostly datasets. If the working set fits in memory, or writes are rare, compaction tuning moves numbers nobody notices. Measure before you spend engineering time on it.
  • Engines that hide the policy. If you are on a managed store or an embedded engine with fixed compaction behaviour, the paper is useful for understanding behaviour, not for changing it.
  • Delete-heavy workloads. Tombstones count against space and slow down range scans until compaction drops them. A write-optimised policy can keep them around much longer than you expect, and disk usage will grow even while live data stays flat.
  • Disk headroom during merges. Large merges need temporary space alongside the inputs. A configuration that looks tight on steady-state space amplification can still run out of disk mid-compaction.
  • Tail latency. Lower average write cost can come with larger, burstier merges. Watch p99 latency, not just throughput.

The lesson that survives any specific result: space amplification is a setting you choose, not a fixed property of LSM-trees. Measure write bytes, runs probed per lookup, and disk-to-live-data ratio on your own workload, then pick the trade-off deliberately.

  • #LSM-tree
  • #compaction
  • #key-value store
  • #leveling vs tiering
  • #space amplification
  • #write amplification

Comments

Add a comment
Sign in with Google to join the conversation