# Behind the doors of key-value stores

- Speaker: [Eran Gilad](/wiki/speakers/eran-gilad.md)
- Event: [Reversim Summit 2022](/wiki/years/2022.md)
- Video: https://www.youtube.com/watch?v=PuyuDvWhH4E
- Transcript: [/transcripts/2022/13-PuyuDvWhH4E.md](/transcripts/2022/13-PuyuDvWhH4E.md)
- Language: Hebrew · Type: talk · Level: intermediate
- Topics: [Databases](/wiki/topics/databases.md), [Performance](/wiki/topics/performance.md), [Algorithms](/wiki/topics/algorithms.md), [Infrastructure](/wiki/topics/infrastructure.md)

> Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

## Summary

This talk explores the internal architecture and design trade-offs of key-value stores, focusing on how different data structures manage data on disk versus in memory. The speaker breaks down five distinct design approaches, including B-Trees, LSM-Trees, and log-plus-index systems, analyzing their impact on read, write, and scan performance. Through this comparison, the audience learns how to evaluate these trade-offs to choose the right database architecture for specific application requirements.

## Key points

- [1:23](https://www.youtube.com/watch?v=PuyuDvWhH4E&t=83s) A key-value store is the most basic type of database, supporting core operations such as put, get, scan, and delete.
- [3:43](https://www.youtube.com/watch?v=PuyuDvWhH4E&t=223s) Working with disk storage requires handling block devices efficiently, meaning reads and writes should be performed in large chunks rather than single bytes.
- [7:01](https://www.youtube.com/watch?v=PuyuDvWhH4E&t=421s) B-Trees organize data into wide, fixed-size nodes mapped to disk blocks, providing efficient sorted range scans and low-depth traversal.
- [16:31](https://www.youtube.com/watch?v=PuyuDvWhH4E&t=991s) LSM-Trees separate fast frequent writes in a memory table and a sequential log from slower background compaction processes across tiered disk files.
- [23:03](https://www.youtube.com/watch?v=PuyuDvWhH4E&t=1383s) Separating keys from values in an LSM architecture allows smaller index structures that fit better in cache, though range scans become less efficient.
- [25:08](https://www.youtube.com/watch?v=PuyuDvWhH4E&t=1508s) Log-plus-index designs keep all keys in main memory for fast gets and puts, but suffer from slow recovery times after server restarts.
- [27:22](https://www.youtube.com/watch?v=PuyuDvWhH4E&t=1642s) Choosing a key-value store design always involves a trade-off between immediate write updates, scan performance, memory usage, and recovery speed.

## Takeaways

- Understand that disk I/O efficiency relies on working with block-sized chunks of data rather than individual bytes.
- Evaluate whether your application prioritizes fast writes (like LSM-Trees) or fast range scans (like B-Trees).
- Consider memory constraints and recovery times when deciding whether to keep indexes in RAM or on disk.

## Questions this talk answers

- What are the core performance differences between B-Tree and LSM-Tree storage engines?
- Why is sequential block I/O preferred over random access when designing disk-based databases?
- How do log-plus-index architectures impact database recovery time after a crash?

## Technologies

Redis, MySQL, RocksDB, LevelDB

## Tags

b-tree, data structures, databases, disk i/o, lsm-tree, performance, storage engines
