How it works
“Faster” means little without a workload. Three ratios say more. Write amplification is bytes written to storage per byte the application wrote. Read amplification is storage reads per query. Space amplification is bytes on disk per byte of live data. High write amplification eats disk bandwidth and wears SSDs, and no design minimizes all three.
Assume updates land all over a table far larger than memory, on 16 KB B-tree pages, with one changed row per flushed page. A 100-byte row then costs 16 KB of page writes, a write amplification of about 160, plus the log. An LSM tree with four levels, each ten times larger than the last, rewrites a byte up to about 10 times per level, so up to about 40, plus the log. Now make the rows 4 KB. The B-tree drops to about 4, while the LSM tree’s figure barely moves, because its cost is per byte rather than per page. The winner flipped. Inserting in key order also helps a B-tree, since each page fills before it is flushed.
Reads lean the other way. A B-tree lookup follows one path, while an LSM lookup may check several files. Bloom filters narrow that gap for point reads but not for range scans, which merge every level. On space, this LSM tree can run near 1.1 times live data, while randomly filled B-tree pages are often about two-thirds full, or near 1.5 times. Start by favoring an LSM tree for write-heavy small records and a B-tree for read-heavy range queries, then benchmark with real data.
You are choosing an engine for a fleet-sensor service: 50,000 writes per second of 200-byte readings, with a primary key of (device, time). Dashboards read one device’s last hour. Storage is your largest cost. Which engine would you start with, and what would you test?
Start with an LSM engine. Small rows scattered across devices would make a B-tree rewrite many pages, while an LSM tree batches them and compresses well. The dashboard read is a short range scan, so test its p99 during heavy compaction, since that is where this choice can hurt. A time-first key would make B-tree inserts sequential and cheap, but it would spread one device’s readings across the index and slow that read.
Use this as a guide for self review; written answers are not graded.Keep in mind
- Compare engines on three ratios: bytes written, reads per query, and disk used per live byte.
- Row size and access pattern, not an engine’s label, decide which one writes less.