The Numbers on Disk
1 — The WAL on disk
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
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 MB4 — 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 missCompaction 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
| Products | 10 million |
|---|---|
| Avg record | 500 bytes |
| Writes | 100 /sec |
| Reads | 10,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 runsBlock size: 4 KB vs 16 KB vs 64 KB
| Aspect | 4 KB | 16 KB | 64 KB |
|---|---|---|---|
| Blocks in a 100 MB SSTable | 25,000 | 6,400 | 1,600 |
| Sparse index size | 200 KB | 51 KB | 12 KB |
| Disk I/O per lookup | 1 small read | 1 medium read | 1 large read |
| CPU scanning per lookup | Minimal | Moderate | High (~64 KB worst case) |
| Compression ratio | Moderate | Good | Excellent (whole block compresses) |
| Best for | Point lookups (KV stores) | Balanced workloads | Scans (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
| Component | Size | Location | Role |
|---|---|---|---|
| Memtable | ~100 MB | RAM | In-flight writes, sorted |
| WAL | ~GB/day | Disk | Crash recovery |
| SSTable | 50–500 MB | Disk | Immutable, sorted, indexed |
| Sparse index | ~100 KB | RAM (from footer) | Locate the right block |
| Bloom filter | ~12 MB | RAM (from filter block) | Prove absence, skip the file |
| Block | 4–64 KB | Disk | I/O unit |
| Compaction overhead | 2–3× | RAM + disk | Temporary, 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.