Database Indexing hard
Why do many in-memory storage engines (e.g., Redis Sorted Sets, MemTables) use Skip Lists instead of Balanced Trees?
- A Skip Lists are mathematically guaranteed to provide constant-time O(1) performance for all find, insert, and delete operations.
- B Skip Lists utilize significantly less physical memory than standard B-Trees because they don't require the storage of complex child pointers.
- C Skip Lists are significantly easier to implement as lock-free data structures, offering superior write concurrency without complex rebalancing logic.
- D Skip Lists are natively cache-oblivious, ensuring that the internal processor cache is always utilized at its maximum theoretical efficiency.
Answer: C. Skip Lists are significantly easier to implement as lock-free data structures, offering superior write concurrency without complex rebalancing logic.
Balanced trees like Red-Black trees require complex global rebalancing (rotations) on insert, which can involve locking large portions of the tree in a multi-threaded environment. Skip lists are probabilistic: they 'rebalance' via a simple random coin flip for each new node. This means inserts are mostly localized, making it much simpler to implement highly concurrent, lock-free operations using Compare-and-Swap (CAS) instructions. This is why tools like Redis and the MemTables in RocksDB/Cassandra favor them for high-throughput write workloads.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- Z-Order Curves (Geohashing) map 2D data to 1D strings for indexing. What is their primary weakness?
- In-Memory databases (Hyper, HANA) often favor Adaptive Radix Trees (ART). Why?
- Log-Structured Merge (LSM) Trees (RocksDB, Cassandra) optimize for Write Throughput. How does their disk IO pattern differ from B-Trees?
- In LSM compaction strategies, 'Universal' (Tiered) compaction prioritizes what over 'Leveled' compaction?
- In LSM trees, what is 'Space Amplification'?
- Why is it generally ineffective to index a 'Low Cardinality' column like `Gender` ('Male'/'Female')?