Senior LevelSystem Design & Architecture
What is Write Amplification in Log-Structured Merge (LSM) Trees?
β Interview Prompt: Explain LSM-Trees (Log-Structured Merge Trees), MemTable, SSTables, SSTable Compaction, and Write Amplification calculations.
Log-Structured Merge (LSM) Trees optimize write performance by buffering writes in an in-memory MemTable and flushing them sequentially to SSTables on disk:
Write Amplification:
β’
Occurs when data is written to disk multiple times due to background SSTable Compaction merges.
β’
Write Amplification Factor (WAF): Ratio of total bytes written to underlying storage vs bytes written by client. High WAF wears out SSD flash memory and consumes disk I/O bandwidth!
Code Implementation Example
markdown
LSM-Tree Write Path and Compaction:
[Client Write] ββ> [MemTable (RAM)] ββ(Flush)ββ> [Level 0 SSTable (Disk)]
β β
(Write-Ahead Log) (Background Compaction)
β
βΌ
[Level 1 SSTable (Disk)]π‘LSM-Tree write path and background SSTable compaction.
π― Interview Key Takeaway
LSM-Trees provide fast sequential writes, but background compaction causes Write Amplification that must be monitored.
#System Design#LSM-Tree#Write Amplification#SSTables#Senior
Back to all System Design & Architecture Questionsβ