Why Two Families Exist

Two families of OLTP storage engine, taken to the bottom. Part I follows the log-structured line — append-only logs, SSTables, memtables, compaction, Bloom filters — as RocksDB and Cassandra actually implement it. Part II follows the in-place line — B-tree pages, heap tuples, MVCC, VACUUM, buffer pool, WAL — as PostgreSQL actually implements it. Part III is the appendix: what happens once you leave OLTP behind. This guide deliberately does not cover distributed replication, consensus, or query planning.

The two-function database

You can build a working key-value store in two lines of bash. It is worth starting here, because the real engines never abandon this shape — they only defend it.

the entire storage engine

db_set() {
  echo "$1,$2" >> database
}

db_get() {
  grep "^$1," database | sed -e "s/^$1,//" | tail -n 1
}

Storage format: a text file, one key,value per line. Multiple entries for the same key are allowed — nothing is ever overwritten — so the current value is simply the last occurrence of that key.

Write — excellent ✓

db_set appends to the end of the file. Appending is one of the cheapest operations a filesystem offers. Real engines keep this property; they only add concurrency control, space reclamation, and crash recovery on top.

Read — unacceptable ✗

db_get scans the whole file. Scanning backwards finds recent keys faster (newest writes are at the end), but the worst case is still O(n): double the records, double the lookup time.

The fix, and its price: indexes

An index is an additional data structure derived from the primary data — typically organized by key — that exists only to make lookups faster. It is optional (add and drop freely), non-intrusive (it never changes the stored data, only query performance), and pluralizable (many indexes over different attributes of the same rows).

The trade-off is structural, not incidental: an index speeds up reads by making every write more expensive — each write must now update the primary data and every affected index. This is why no database indexes everything by default, and why choosing indexes stays a human decision driven by known query patterns.

The two OLTP families

Given that trade-off, there are two coherent ways to organize the data itself:

A storage engine serves one of two workloads. OLTP, frequent small reads and writes, splits into two families by how a write touches the file: log-structured engines append immutable files (Part I, the LSM tree), in-place engines overwrite fixed-size pages (Part II, the B-tree). OLAP, full-table scans and aggregations, is served by column stores and table formats (Part III). Spatial and full-text indexes (Part IV) are built on top of either OLTP family.
One fork on the workload, one on how a write touches the file — the guide follows both

Both families are used for primary key-value storage and for secondary indexes — the choice is about the file layout, not about what the structure is used for. Beyond these, databases layer on multidimensional indexes (for geospatial and multi-column range queries) and full-text indexes (for search). Both are in Part IV — see Multidimensional indexes and Full-text indexes.

Who actually uses what

StrategyDatabases
LSM-tree / log-structured — memtable + SSTables Part IRocksDB, LevelDB, Cassandra, HBase, ScyllaDB, InfluxDB
B-tree — in-place page updates Part IIPostgreSQL, MySQL (InnoDB), SQLite, Oracle, SQL Server
In-memory — RAM-primary, disk only for durabilityRedis, Memcached (no durability), VoltDB, SAP HANA, Oracle TimesTen
Column-store / OLAP — analytics, full scansSnowflake, BigQuery, Redshift, Vertica, ClickHouse, Teradata
HTAP — transactional + analytical in one systemSingleStore, SAP HANA, Microsoft SQL Server

The Invariants

  • Guarantees: An append-only log gives you the cheapest possible write and a complete history of changes, on any hardware.
  • Does not guarantee: Any bound on read cost, any bound on disk growth, or any way to answer a range query — all three must be bought back with additional structure.