Describe how a write moves through an LSM tree.
Sketch your own answer first, then compare it with the one below.
A strong answer
The write is appended to a log for durability and inserted into the memtable, a sorted table in memory. When the memtable is full, it is written to disk in one sequential pass as an immutable sorted file, an SSTable.
Over time files pile up. A background process, compaction, merges them into larger sorted files and drops old versions of keys.
The write itself never changes an existing file. That is what makes writes fast and sequential, and why reads have to look in more than one place.
Sources
- Patrick O'Neil, Edward Cheng, Dieter Gawlick, Elizabeth O'Neil (1996). The log-structured merge-tree (LSM-tree).
- Fay Chang, Jeffrey Dean, Sanjay Ghemawat, Wilson C. Hsieh, Deborah A. Wallach, Mike Burrows, Tushar Chandra, Andrew Fikes, Robert E. Gruber (2008). Bigtable: A Distributed Storage System for Structured Data.