Unit 7 of 12 · about 4 hours · derive, implement
LSM levels, memtable flush, SSTables and Bloom filter false positives
Write-heavy stores accept background merge work to keep foreground writes sequential. The Bloom filter is what keeps the resulting multi-level reads affordable.
You'll be able to
- Derive the Bloom filter false-positive rate from bits per key and hash count.
- Explain memtable insert, immutable freeze, flush and leveled organization with overlap rules.
- Size a Bloom filter for a stated key count and rate target.
Covers
Read
In this order, only the parts listed
0 of 3 done
- LSM trees and SSTablesDDIA 2e - Chapter 4 Storage and Retrieval
Chapter 4, Log-Structured Storage, printed pp. 118-124: SSTables, memtables, sorted-run merging and the Bloom filter and compaction strategy notes, then Comparing B-Trees and LSM-Trees, printed pp. 129-131
The Bloom filter and tombstone treatments here are brief; take the sizing math from the HLD sizing page in this unit.
- HLD Handbook LSM mechanics and Bloom filtersHLD Handbook - Storage Engines and Data Structures
LSM-tree mechanics with the 64 MB memtable and 10x level growth, then Bloom filters and read optimization with the 10-bits-per-key 1% rule
Treat the RocksDB defaults as examples that label the mechanism, not as settings to copy blindly.
- Bloom filter sizing formulaHLD Handbook - Storage Engines and Data Structures
Bloom filters: the bit array mechanism with and , the 1% worked sizing and the RocksDB 10-bits-per-key default
Focus on
- Writes land in a sorted memtable. A full memtable freezes to immutable, flushes as one sorted SSTable, and a new memtable takes over without blocking the ack path.
- Level 0 files overlap because each is a direct flush. Deeper levels hold non-overlapping sorted runs, so a read checks every L0 file but at most one file per deeper level.
- A Bloom filter has no false negatives and a tunable false-positive rate . Negatives skip the SSTable; positives still read it. Optimal hash count is , so 10 bits per key uses 7 hashes for about 1% and 16 bits per key uses 11 hashes for about 0.05%.
- Bloom filters do not help range scans. A range must open every overlapping run because hashing every key in the range is impractical.
Common mistakes · 3
- Reading a negative Bloom answer as uncertain. Negative is certain absence; only positive answers are probabilistic.
- Adding hash functions past the optimum to lower the rate. Excess hashes fill the bit array faster and the rate rises again.
- Treating Level 0 as non-overlapping. Overlap is the defining L0 property and the reason reads check every L0 file newest first.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.A memtable fills while a flush is still running. Where does the next write go?Answer
Into a new active memtable. The full one is already immutable, so foreground writes never wait for the flush to finish; backpressure only starts if immutable tables pile up.
2.With bits per key, which integer minimizes the rate and what is it?Answer
About , so , giving roughly 0.8%. That is the 1% rule quoted for 10 bits per key.
3.A point lookup misses in every Bloom filter. How many SSTable reads happen?Answer
None for the skipped files. The filters rule out every level, so the read returns not-found without loading data blocks.
4.Why keep deletes as tombstones instead of removing the key during the flush?Answer
Older levels may still hold the key. Removing it only from the new file would resurrect the stale copy on reads; the tombstone must compact through every level that can contain the key.
Practice
- CMU 15-445 Fall 2025 Homework #3: Bloom Filter
Question 4, Bloom Filter: the bit-array walkthrough and the true-or-false Bloom statements
Work the 8-bit example by hand, then check against the published solutions. Keep the B+ tree project for the index unit.
You're done when
You derive the rate for a new bits-per-key value without notes and can state which SSTable files a point read touches.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 11 more in the section
- DDIA 2e - Chapter 4 Storage and RetrievalMartin Kleppmann and Chris Riccomini · required
Read "Storage and Indexing for OLTP" (log-structured storage, B-trees, their comparison and secondary indexes) and "Data Storage for Analytics" (column-oriented storage). Its Bloom filter, tombstone and write-ahead log coverage is brief, so take those from OSTEP and The Internals of PostgreSQL. Build a workload decision table, then connect each claim to a measurement from your small store.
- HLD Handbook - Storage Engines and Data StructuresHLD Handbook · required
Read Part 0 data structures plus Part 4 storage engines and OLTP versus OLAP. Use its exercises for comparison, while the CMU project and local fault tests remain the implementation evidence.
Also in this section
- CMU 15-445 - Storage, Index and Recovery SequenceCarnegie Mellon Database Group · primary
Follow Fall 2025 lectures 3 to 10 and 21 to 22. Do the BusTub projects from tag v20251119-2025fall (https://github.com/cmu-db/bustub/tree/v20251119-2025fall): P1 (ARC replacer, disk scheduler and buffer pool manager) and P2 (B+ tree with a leaf tombstone buffer), with P0 (Count-Min Sketch) as the C++ warm-up. Tests ship with a
DISABLED_prefix to remove, and GCC 15 needs-DCMAKE_CXX_FLAGS="-include cstdint"at configure time. Use the storage and recovery homework for WAL reasoning, and keep C++ scope bounded to storage and recovery. - Hypothesis - Stateful TestingHypothesis · support
Use
RuleBasedStateMachinewith rules, bundles and invariants to drive your store and a dictionary model with the same random operation sequences, and check the machine catches a planted bug before trusting a pass. - Building Distributed Systems - The Logger and IndexesBuild Distributed Systems · optional
Only the first three tasks are free (a write-ahead log, its recovery and log segments). Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.
- The Internals of PostgreSQL - Buffer Manager, WAL and RecoveryHironobu Suzuki · support
Read Chapter 1 Sections 1.2 to 1.4 (heap pages and tuples), Chapter 8 (buffer manager and dirty-page flushing) and Chapter 9 Sections 9.1 to 9.8 (WAL segments, XLOG records, checkpoints and recovery). Compare each mechanism with your simplified store. The site is revised often, so note the date you read it.
- PostgreSQL 18 Documentation - WAL Configuration and InternalsPostgreSQL Global Development Group · support
Read "WAL Configuration" (checkpoints and the redo point crash recovery starts from), "WAL Internals" and "Reliability" for the official, versioned statement of the write-ahead and durability contract.
- Operating Systems: Three Easy Pieces - Crash Consistency and Data IntegrityRemzi and Andrea Arpaci-Dusseau · required
Read Chapter 42 (FSCK and journaling: the crash scenarios, data and metadata journaling and their write order) and Chapter 45 (data integrity: checksums, misdirected and lost writes, scrubbing; https://pages.cs.wisc.edu/~remzi/OSTEP/file-integrity.pdf). Turn each crash scenario into an injection point in your store.
- ARIES: A Transaction Recovery Method (Mohan et al., 1992)ACM TODS (Stanford course copy) · support
Read the introduction, the overview and restart processing (analysis, redo by repeating history, undo) and the page LSN rule. The rest is 1992 storage detail beyond this section.
- Build Your Own RedisBuild Your Own · optional
Use the persistence and data-structure portions only if a second implementation is needed to cement parsing, indexing or append-log behavior. Do not replace the crash-tested stage artifact with tutorial completion.
- Replicated Log and Stream Processor - Storage SliceRoadmap-Final · support
Implement checksummed segments, indexes, acknowledgement states, recovery, retention and atomic metadata changes. Preserve every crash schedule and corrupted artifact needed to reproduce a failure.
- Apache Parquet File FormatApache Software Foundation · support
Read the File Format layout (row groups, column chunks, footer metadata) and the Page Index page (ColumnIndex and OffsetIndex with per-page min and max values for page skipping). Use it only for file layout and skipping; it does not cover table metadata or catalogs.
- Linux man-pages: fsyncLinux man-pages project · support
Read the DESCRIPTION for what
fsyncandfdatasyncguarantee and the directory-sync requirement for new file names, and the ERRORS section for what anEIOfrom write-back can refer to.