DataLSM treelog-structured merge treeBitcaskcompactionappend-only log

Log-structured storage

Definition

Log-structured storage never updates data in place: every write is appended to a log or a sorted file, an index finds the latest version of each key, and compaction rewrites files to discard old versions.

In practice

Sequential appends are much faster than random in-place writes, so log-structured engines handle heavy write loads well. Bitcask keeps an in-memory hash of every key pointing into an append-only file; LSM trees (RocksDB, Cassandra, ScyllaDB) buffer writes in memory and flush sorted files that are merged level by level. Recovery replays or reloads the log.

Reads may have to check several files, which Bloom filters and caches soften. Compaction consumes disk bandwidth and CPU in the background and can cause latency spikes if it falls behind. Deleted keys linger as tombstones until compaction removes them. Compared with B-trees, LSM trees trade read cost and space for cheaper writes.

Example

A Bitcask store appends SET cart:9 = [...] to the active data file and updates the in-memory hash; compaction later rewrites files to keep only the newest value of each of its 5 million keys.