The Numbers on Disk

1 — The WAL on disk

The WAL file wal-123.log: a 4-byte magic number header, then timestamped entries in arrival order — write key1 = value1, write key2 = value2, write key1 = value1-updated, delete key3 — and the next append goes on the end; nothing is ever overwritten, so the update to key1 is a new entry. Each entry is about 100 to 200 bytes; at 1,000 operations per second and 150 bytes each that is 150 KB per second, about 1 GB of WAL every 2 hours. The file is cleared once its memtable successfully flushes.
The WAL is one append-only file of operations, freed at the next flush

Hardware impact: WAL writes are purely sequential — SSD ~1–2 GB/s, HDD ~100 MB/s. On spinning disks the per-write fsync is what caps write throughput, not the data volume.

2 — The memtable in RAM

Memtable (red-black tree, ~100 MB threshold):
  ├─ Node: key="alice",   value="30"
  ├─ Node: key="bob",     value="25"
  ├─ Node: key="charlie", value="28"
  └─ (tree pointers, colour bits, heights for balancing)

100 MB user data + ~15 MB tree structure = ~115 MB RAM  (~10–15% overhead)

On flush: in-order traversal → key-value pairs written sequentially to a new SSTable → sparse index built (one entry per ~4 KB block) → the whole tree deallocated → a new empty memtable starts accepting writes.

3 — Inside one SSTable file

The layout of sstable-001.sst, produced by one 100 MB memtable flush, top to bottom. Data blocks, about 95 MB: sorted key-value pairs in about 4 KB blocks — block 1 holds alice = 30 and amelia = 31, block 2 starts with bob = 25, and there are about 23,750 more. The Bloom filter, about 12 MB: a bit array at 10 bits per key for about a 1 percent false-positive rate. The sparse index block, about 100 KB: one entry per data block giving its first key and byte offset — alice at byte 0 points to block 1, bob at byte 4,096 points to block 2. The footer, about 4 KB: format version, checksums, codec, and the offset of the index block.
sstable-001.sst — what one 100 MB memtable flush puts on disk

why ~95 MB and not 100 MB

Original memtable data:                      100 MB
  − multiple versions of the same key (latest kept)   ~5%
  − deleted (tombstoned) keys removed                 ~2%
  − LZ4 / Snappy block compression                    ~8%
  + additional metadata overhead                      ~1%
                                             = ~86 MB
  + index + filter blocks                    +  ~9 MB
                                             = ~95 MB

4 — What accumulation actually costs

Every flush adds one SSTable, and nothing removes old ones until compaction runs. Take the 100 MB memtable from above, flushing once an hour for 5 days with no compaction:

5 days of hourly flushes, no compaction

Files:  24 flushes/day × 5 days               = 120 SSTables
Disk:   120 × 95 MB                            ≈ 11.4 GB
        but only ~5–6 GB is live data; the rest is old versions and deleted keys
RAM:    every open SSTable keeps its index + Bloom filter in memory
        ~100 KB + ~12 MB                       ≈ 12.1 MB per file
        120 × 12.1 MB                          ≈ 1.45 GB of metadata alone
Reads:  a missing key checks all 120 filters
        120 × 1% false positives               ≈ 1 wasted block read per miss

Compaction pays this down. Merge the 10 oldest files into one:

one size-tiered compaction of the 10 oldest files

Read:   10 files                               950 MB
Merge:  keep the newest version of each key, drop the rest
Write:  1 file                                ~850 MB   (100 MB of old versions gone)
Cost:   950 read + 850 write = 1,800 MB, ~5 s of sequential I/O on an SSD

Files:  120 → 111
Disk:   11.4 GB → 11.3 GB
RAM:    barely moves. Filter size follows key count, not file count, so the merged
        file's filter is ~850/95 × 12 MB ≈ 107 MB. Only the dropped keys free RAM.

What compaction really buys is fewer files and less dead data. Fewer files means fewer filters and indexes to check on every read. Less dead data means less disk. Filter RAM only shrinks as fast as duplicate and deleted keys are thrown away.

Real-world sizing: an e-commerce product catalog

Products10 million
Avg record500 bytes
Writes100 /sec
Reads10,000 /sec
Raw data:        10M × 500 B                     = 5 GB
Memtable:        100 MB threshold                ≈ 200,000 records per flush
Write volume:    100/s × ~500 B                  ≈ 4.3 GB/day → ~43 flushes/day
WAL:             same 4.3 GB/day, each segment freed once its memtable flushes

SSTables after 30 days if nothing compacts:
  30 × ~50                                       ≈ 1,500 SSTables, ~150 GB of flushes
  ...for 5 GB of unique data — the rest is overwritten versions
After leveled compaction                         ≈ 5.5 GB on disk, ~150 files

Indexes + filters, per 100 MB SSTable of 500 B records:
  200,000 keys × 10 bits                         = 250 KB filter (+ ~100 KB sparse index)
  1,500 SSTables × ~350 KB                       ≈ 525 MB  ← fits in RAM; RAM is not the problem
    150 SSTables × ~350 KB                       ≈  53 MB

The false-positive bill on a miss (product does not exist):
  1,500 files × 1% FP                            ≈ 15 spurious sparse-index probes + block reads
    150 files × 1% FP                            ≈ 1.5 — and leveled's per-level key-range
                                                    check skips most files before the filter runs

Block size: 4 KB vs 16 KB vs 64 KB

Aspect4 KB16 KB64 KB
Blocks in a 100 MB SSTable25,0006,4001,600
Sparse index size200 KB51 KB12 KB
Disk I/O per lookup1 small read1 medium read1 large read
CPU scanning per lookupMinimalModerateHigh (~64 KB worst case)
Compression ratioModerateGoodExcellent (whole block compresses)
Best forPoint lookups (KV stores)Balanced workloadsScans (analytics)

Standard choice: ~4 KB for OLTP key-value workloads, ~64 KB for OLAP scan workloads. The sparse-index sizing rule from the SSTables and sparse indexes part is the same rule seen from the other end — bigger blocks mean fewer index entries and a longer in-block scan.

Real hardware costs

✓ Write — flushing a 100 MB memtable

NVMe SSD:  3–4 GB/s   → 100 MB in  25 ms
           IOPS 100,000+
SATA HDD:  150 MB/s   → 100 MB in 670 ms
           IOPS ~200

SSD ~27× faster. Both are sequential I/O;
HDD mechanical latency dominates.

✗ Read — key not found across 100 SSTables (HDD)

With Bloom filters (all in RAM):
  100 checks × ~50 ns = 5 µs
  + ~1 false positive (1% × 100) × 3 ms block read
  → ~3 ms on HDD, well under 1 ms on SSD

Without Bloom filters:
  100 × (index lookup 100 ns + block read 3,000 µs)
  → 300,000 µs = 300 ms
  (99.7% of it spent on disk I/O)

Bloom filter benefit on misses: ~100–300×
Random vs sequential latency:

Modern SSD:  random read 100–500 µs;  sequential same bandwidth, no seek
Modern HDD:  random read 3–10 ms (mechanical seek);  sequential 150 MB/s

  → SSD:  random and sequential are nearly equivalent
  → HDD:  sequential is ~50–100× faster than random

This is why the SSTable design optimizes for sequential I/O: it is merely
good on SSD, and it is the difference between working and not on HDD.

Recap: the whole architecture in one table

ComponentSizeLocationRole
Memtable~100 MBRAMIn-flight writes, sorted
WAL~GB/dayDiskCrash recovery
SSTable50–500 MBDiskImmutable, sorted, indexed
Sparse index~100 KBRAM (from footer)Locate the right block
Bloom filter~12 MBRAM (from filter block)Prove absence, skip the file
Block4–64 KBDiskI/O unit
Compaction overhead2–3×RAM + diskTemporary, during merge

Coda: embedded storage engines

Most of the above assumes a database running as a network service. Embedded databases run as a library inside your application process: they read and write local files and are called through ordinary function calls, with no network API. Examples: RocksDB, SQLite, LMDB, DuckDB, KùzuDB.

Where they fit: mobile apps storing local user data; backend systems whose data fits on one machine with limited concurrent transactions; and multitenant systems where each tenant is small and fully isolated — you can run a separate embedded instance per tenant, provided queries never need to combine data across tenants.

The Invariants

  • Guarantees: Write cost stays sequential at every layer (WAL append, memtable flush, compaction merge), which is what makes the design portable across SSD and HDD.
  • Does not guarantee: That per-SSTable RAM overhead stays affordable. Index + filter footprint scales with file count, so it is bounded only by how well compaction keeps up.