Scrivio Interview library
DesignPrincipal7 min read · updated 12 November 2026

Log-structured merge trees replaced B-trees in many newer storage engines (RocksDB, Cassandra), while PostgreSQL and MySQL InnoDB still use B-trees. As the person setting data platform direction, how do you explain the trade-off and decide which engines your company supports?

B-trees update pages in place, which gives predictable read latency and efficient range scans but costs write amplification from random page writes. LSM trees buffer writes in memory and flush them as sorted, immutable files, which gives very high write throughput at the cost of read amplification and ongoing compaction work. So write-heavy event and time-series data suits LSM engines and transactional workloads with complex queries suit B-tree relational databases. As a platform owner, I would support a small catalogue, for example PostgreSQL as the default and one LSM-based store for proven high-write cases, because every extra engine multiplies operational skill, tooling and on-call burden, and managed services do not remove the need to understand compaction and tuning.

Background to this question

Storage engine choices outlive almost every other technical decision: data migrations are slow, risky and expensive. When teams ask for Cassandra or RocksDB because they are fast at writes, or for PostgreSQL because it does everything, the person setting direction has to explain the trade-off in plain terms and turn it into a policy. In this answer, we will recap how B-trees and LSM trees store data, compare their costs in terms of write, read and space amplification, map workloads to engines, and then decide how many engines the company supports and how exceptions work.

1How a B-Tree Engine Writes

PostgreSQL and MySQL's InnoDB store tables and indexes in B-tree structures made of fixed-size pages. To update a row, the engine finds the page that holds it, changes it in memory, and records the change in a write-ahead log (WAL) so it can recover after a crash. Later, the changed page is written back to its place on disk.

This in-place design keeps every key in exactly one known location, so a read follows one path from the root to a leaf, and a range scan walks neighbouring leaves. Reads are fast and predictable. The cost falls on writes: changing a 100-byte row can mean writing a whole 8 KB or 16 KB page, plus WAL records, plus extra protections against torn pages (PostgreSQL's full-page writes after a checkpoint, InnoDB's doublewrite buffer). With random keys, writes are scattered across the disk. The ratio of bytes written to disk to bytes the application changed is called write amplification, and for B-trees under random updates it can be large.

2How an LSM-Tree Engine Writes

A log-structured merge tree, used by RocksDB, Cassandra, ScyllaDB and others, never updates data in place. A write goes into the commit log for durability and into an in-memory sorted table called the memtable. When the memtable is full, the engine flushes it to disk as an immutable sorted file (an SSTable). Writes are therefore sequential and cheap, which is why LSM engines absorb very high write rates.

The cost moves to reads and background work. A key may exist in the memtable and in several SSTables, with the newest version winning, so a read may check several files: that is read amplification. Bloom filters, small probabilistic summaries that say "this key is definitely not in this file", keep point reads fast, but range scans must merge several files. To stop files piling up, the engine runs compaction, merging SSTables and dropping overwritten and deleted values. Compaction rewrites data repeatedly, so LSM engines have their own write amplification, and it competes with foreground traffic for disk and CPU. Deletes are written as markers called tombstones, which linger until compaction removes them.

Step throughA write and a read in an LSM engine
ClientMemtable + logSSTablesCompaction
write key=42: append to log, insert into memtable
acknowledged, no random disk write
memtable full: flush as a new sorted file
merge older files, drop overwritten values and tombstones
read key=42: check memtable first
then newest to oldest files, skipping via Bloom filters
newest version of key 42

7 messages in order. Play them, or step through them one at a time.

Writes are cheap and sequential; reads and compaction pay the cost later.

3Comparing the Costs

A useful way to explain the trade-off to non-specialists is the three amplifications: how many extra bytes each engine writes, reads and stores per byte of real work. Neither engine is better overall; each moves the cost to a different place.

B-tree and LSM engines compared
AspectB-tree (PostgreSQL, InnoDB)LSM (RocksDB, Cassandra)
Write pathupdate pages in place, random I/Oappend and flush sorted files, sequential
Write throughputgood, drops with random keysvery high
Point readone root-to-leaf path, predictablememtable plus files, helped by Bloom filters
Range scanwalk linked leavesmerge several sorted files
Background workvacuum or purge, checkpointscompaction, a constant tuning concern
Spacefragmentation, bloatold versions until compaction
Typical fitOLTP, joins, constraints, ad hoc queriesevents, time series, high-write key-value

4Matching Workloads to Engines

The workload decides more than benchmarks do. Transactional data with relationships, constraints and changing query needs, such as orders, accounts, inventory and bookings, belongs in a relational B-tree database. It gives transactions across rows, foreign keys, secondary indexes, joins and a mature query planner, and its read latency is predictable.

Write-heavy, append-mostly data with simple access patterns, such as event logs, metrics, IoT readings, activity feeds or per-user time series queried by key and time range, suits an LSM engine. If a team needs to ingest 200,000 writes per second across a cluster and reads by partition key and time, Cassandra or ScyllaDB fit naturally. RocksDB also appears inside other systems, for example as the state store of Kafka Streams applications, so many companies already run LSM engines without having chosen one.

Many workloads in the middle fit fine in PostgreSQL at moderate scale, with partitioning for time series. The question to ask a team is not which engine is faster, but what the access patterns, write rate, consistency needs and growth are, and whether the default can meet them.

5Deciding Which Engines the Company Supports

Every engine we support needs people who understand it at 3 a.m., backup and restore procedures that have actually been tested, monitoring, capacity planning, security patching, client libraries and upgrade paths. Supporting six engines means six sets of all of that, usually done badly. So I would keep the catalogue small: a relational default, PostgreSQL, for most services; one LSM-based store for proven high-write workloads; and the caches and search engines we already run. Each supported engine has an owning platform team, a paved path (templates, client configuration, dashboards) and on-call coverage.

Teams that want something outside the catalogue write a short case: the workload, why the supported engines cannot meet it, with numbers, and who will operate the new one. Most requests end with the team using the default with better schema design or partitioning, and the few that pass become well-supported additions rather than orphans.

Step throughChoosing an engine for a new workload
  1. Can the default relational database meet it?
    YesUse PostgreSQL with the paved pathNoContinue
  2. Is it write-heavy with key and time access?
    YesUse the supported LSM storeNoContinue
  3. Write an exception caseworkload, numbers, operator
  4. Approved by the platform review?
    YesAdd with an owner and runbooksNoRedesign on a supported engine

4 steps in order. Play them, or step through them one at a time.

6What Managed Services Change and What They Do Not

Managed offerings take away a lot of work: provisioning, patching, backups, failover and some scaling. They do not take away the need to understand the engine. A managed LSM store still needs a compaction strategy that suits the workload, data models designed around partition keys, attention to tombstones from deletes and TTLs, and capacity for compaction headroom. A managed PostgreSQL still needs vacuum tuning, index design and query plans that do not degrade. Managed services also bring their own limits and pricing models, where heavy write amplification can turn directly into cost. So the catalogue still needs in-house expertise for each engine, even when the operations are bought.

7Follow-up questions

Why is read latency less predictable in LSM engines?

Because the number of files a read touches depends on the compaction state. When compaction falls behind under heavy writes, more SSTables accumulate, reads check more of them, and tail latency rises. B-tree reads always follow one root-to-leaf path, so their cost is steadier.

Do B-tree databases have anything like compaction?

They have related housekeeping. PostgreSQL's MVCC keeps old row versions that vacuum must clean up, and InnoDB purges old undo records. Neither rewrites the whole data set repeatedly the way LSM compaction does, but both need monitoring and tuning.

How would you handle a team that already runs an unsupported engine?

Treat it as an exception to be either adopted or retired. If the workload genuinely needs it and the team can show it operates well, we bring it into the catalogue with an owner. If not, we plan a migration to a supported engine on a realistic timeline, starting with new data.

8Conclusion

In this answer, we saw that B-trees update pages in place, giving predictable reads and efficient range scans but write amplification from random page writes, while LSM trees buffer writes in a memtable and flush sorted immutable files, giving high write throughput at the cost of read amplification and compaction. Write-heavy event and time-series data suits LSM engines and transactional workloads with complex queries suit relational B-tree databases. Because every engine multiplies operational skill, tooling and on-call burden, we support a small catalogue with a case process for exceptions, and managed services reduce operations but not the need to understand compaction and tuning.

What to say in the interviewAbout 90 seconds aloud

Open with

I would explain it as where each engine puts the cost. A B-tree engine like PostgreSQL or InnoDB updates pages in place: each key has one home, so reads follow one root-to-leaf path and range scans walk linked leaves, which gives predictable read latency.

Then, if they want more

The price is on writes: changing a small row means rewriting a whole page plus the log, and random keys scatter those writes, so write amplification is high. An LSM engine like RocksDB or Cassandra appends to a log and an in-memory memtable, then flushes sorted immutable files, so writes are sequential and throughput is very high.

The price is on reads, which may check several files, helped by Bloom filters, and on compaction, which keeps merging files in the background and needs tuning. So write-heavy, append-mostly data with key and time access, events, metrics, time series, suits LSM; transactional data with joins, constraints and changing queries suits a relational B-tree database.

For the platform, I would keep the catalogue small: PostgreSQL as the default and one LSM store for proven high-write cases, each with an owning team, paved paths and on-call, because every extra engine multiplies skills, tooling and incidents. Exceptions need a written case with numbers and an operator.

And managed services help with operations, but teams still need to understand compaction and tuning.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Log-structured merge trees replaced B-trees in many newer storage engines (RocksDB...": https://scrivio-interview-library.netlify.app/java/algorithms-and-data-structures/9226161640/