B-tree vs LSM tree

A B-tree updates pages in place, so each write can cost random disk work. An LSM tree appends writes to a log and merges them later. With 6,000 metric writes/s on 1 vCPU, the B-tree store falls behind and the LSM store keeps p99 near 25 ms.

Play the level

A disk that fillsArrow keys change the write rate. Tap to ship the logs.

5 MB/s · logs kept on the host · disk full in 33 minutes

An index against a full scanTap to add or remove the index

Index · 4 pages read per query · disk writes per insert: 2

Case 1

One stream appends 6,000 metric values/s. A catalog serves 4,000 indexed reads/s. Each store has 1 vCPU, and both need p99 under 100 ms.

Case 1
Measure Goal B-tree for both LSM for metrics
p99 latency (Metrics) under 100 ms 10.1 s Fail 25 ms Pass
p99 latency (Catalog) under 100 ms 25 ms Pass 25 ms Pass
Monthly cost 16 USD/mo 16 USD/mo
Error rate 56.1% 0%
SQLSQLUsersUsersPostgres1 vCPU · 2 GBPostgres1 vCPU · 2 GB
SQLSQLUsersUsersPostgres1 vCPU · 2 GBPostgres1 vCPU · 2 GB
B-tree for both: misses a goal
TCPSQLUsersUsersKey-value s…1 vCPU · 2 GBPostgres1 vCPU · 2 GB
TCPSQLUsersUsersKey-value…1 vCPU · 2 GBPostgres1 vCPU · 2 GB
LSM for metrics: meets the goals