Hard Data Structures Advanced Structures
Explain LSM Trees and why they are used in write-optimized databases.
Answer
Log-Structured Merge Trees optimize write-heavy workloads by converting random writes to sequential writes. Writes go to an in-memory buffer (memtable); when full, it flushes to disk as sorted immutable file (SSTable). Background compaction merges SSTables. Reads check memtable then SSTables (aided by bloom filters). Writes are O(1) amortized, reads are slower than B-trees but acceptable with optimizations. Used in LevelDB, RocksDB, Cassandra, and HBase.
IIT Certified
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.
Relevant for Roles
Database Developer Storage Systems Engineer Backend Architect