Database / RocksDB Basics Interview Questions
1. What is RocksDB?
RocksDB is a high-performance, embedded key-value store, a storage engine library that applications link directly into their own process, developed by Facebook (Meta) and optimized for fast storage like SSDs and RAM. Written in C++, and built on a log-structured...
2. Who developed RocksDB?
RocksDB was developed by Facebook, now Meta, as an evolution of Google's earlier LevelDB project. Originally forked from LevelDB and heavily extended to meet Facebook's own performance and scale requirements Released as an open-source project, widely adopted well beyond its...
3. What is RocksDB based on?
RocksDB is based on LevelDB, an earlier embedded key-value store originally created by Google. Kept LevelDB's core design: a log-structured merge-tree with memtables and SSTables Added significant extensions, including column families, additional compaction styles, backup and checkpoint support,
4. What is a Key-Value Store?
A key-value store is a type of database that stores data as simple pairs, a unique key mapped to an associated value, without the fixed rows, columns, or schema of a relational database. Supports basic operations like storing a value...
5. Define the LSM-Tree (Log-Structured Merge-Tree)?
A Log-Structured Merge-Tree is a data structure designed to make writes fast by turning random writes into sequential ones, at the cost of some added complexity on the read path. New writes go into an in-memory structure first, rather than...
6. What is a MemTable in RocksDB?
A MemTable is RocksDB's in-memory buffer that absorbs all new writes before they're ever touched by disk. Every Put, Delete, or Merge operation is applied to the active MemTable first Keeps data in sorted order, so it can be flushed...
7. What data structure implements RocksDB's default MemTable?
RocksDB's default MemTable implementation uses a skip list to keep incoming writes ordered by key. A skip list supports efficient, roughly logarithmic-time insertion and lookup, similar in spirit to a balanced tree Keeping the MemTable sorted means it can be...
8. What is a Write-Ahead Log (WAL) in RocksDB?
The Write-Ahead Log is a sequential, on-disk log that RocksDB appends every write to, in addition to applying it to the in-memory MemTable. Provides durability, if the process crashes before a MemTable is flushed to disk, the WAL can be...
9. What is an SSTable in RocksDB?
An SSTable, or Sorted String Table, is the immutable, on-disk file format RocksDB uses to store key-value pairs once they're flushed out of memory. Stores keys in sorted order, which enables efficient binary search and range scans Once written, an...
10. What is Flushing in RocksDB?
Flushing is the process of writing a full, immutable MemTable's contents out to disk as a new SSTable. Triggered once the active MemTable reaches its configured size limit The full MemTable is marked immutable, and a new, empty MemTable takes...
11. What is Compaction in RocksDB?
Compaction is the background process that merges multiple SSTables together, removing outdated or deleted data and keeping the overall storage structure efficient to read from. Combines SSTables with overlapping key ranges, producing a smaller number of more organized files Physically...
12. What are the Compaction Styles supported by RocksDB?
RocksDB supports a few different strategies for how it merges SSTables together over time. Style Description Leveled compaction Organizes SSTables into levels of increasing size, merging and pushing data down to lower levels over time Universal compaction Keeps SSTables sorted...
13. Define Leveled Compaction?
Leveled compaction organizes SSTables into a series of levels, L0 through Ln, where each level is typically several times larger than the one above it. Level 0 holds SSTables flushed directly from MemTables, and their key ranges may overlap From...
14. Define Universal Compaction?
Universal compaction, sometimes called tiered compaction, keeps SSTables organized by age rather than by strict, non-overlapping key ranges across levels. New SSTables are added to a sorted run, and periodically a group of runs gets merged together into a larger...
15. What is a Bloom Filter in RocksDB?
A Bloom filter is a compact, probabilistic data structure attached to each SSTable that can quickly tell whether a key is definitely not present, without needing to actually read the file. Can produce false positives, occasionally saying a key might...
16. What is an Index Block in an SSTable?
An Index Block is a section within an SSTable that maps key ranges to the specific data block containing them, letting RocksDB jump directly to the right location instead of scanning the whole file. Acts like a table of contents...
17. What is a Block Cache in RocksDB?
The Block Cache is an in-memory cache that holds recently accessed data and index blocks from SSTables, reducing how often RocksDB needs to read from disk. Frequently accessed, or "hot," blocks stay in memory rather than being re-read from disk...
18. What is the Manifest file in RocksDB?
The Manifest is a metadata file that tracks the current set of SSTables and their organization into levels, essentially recording the database's structural state over time. Records every change to which SSTables exist and which level they belong to Used...
19. What are Column Families in RocksDB?
Column Families let a single RocksDB database instance maintain multiple, independently configured, logically separate key spaces within the same database. Each column family can have its own compaction style, comparator, and other tuning options All column families in a database...
20. What is a Comparator in RocksDB?
A Comparator defines how RocksDB orders keys, determining what "sorted" actually means for a given database or column family. The default comparator sorts keys as raw bytes, in straightforward lexicographic order Applications can supply a custom comparator to sort keys...
21. What is a Snapshot in RocksDB?
A Snapshot is a consistent, read-only view of the database's state at a specific point in time, unaffected by writes that happen after it was taken. Lets a read operation see the database exactly as it looked at snapshot creation,...
22. What is an Iterator in RocksDB?
An Iterator lets an application traverse a range of keys in sorted order, rather than looking up one key at a time. Can be positioned at the beginning, at a specific key via a seek operation, or moved forward and...
23. What is the purpose of the Put operation in RocksDB?
Put is the core write operation in RocksDB, used to insert a new key-value pair or overwrite the value of an existing key. Writes go to both the active MemTable in memory and the write-ahead log on disk If the...
24. What is the purpose of the Get operation in RocksDB?
Get is the core read operation in RocksDB, used to retrieve the value currently associated with a specific key. Checks the active MemTable first, then any immutable MemTables waiting to be flushed, then SSTables from Level 0 downward Uses Bloom...
25. What is the purpose of the Delete operation in RocksDB?
Delete marks a key as removed, rather than immediately erasing any existing data for that key from disk. Writes a special marker, often called a tombstone, associated with that key, rather than searching for and physically removing prior values right...
26. What is a Tombstone in RocksDB?
A Tombstone is the marker RocksDB writes to record that a key has been deleted, without immediately removing any of that key's prior data from disk. Behaves like any other write, it goes through the MemTable and WAL just like...
27. What is Merge in RocksDB?
Merge is a special write operation that lets an application apply an incremental update to a key's value without first reading its current value. Common example: incrementing a counter, where you want to add a value rather than overwrite the...
28. What is Write Amplification?
Write amplification is the ratio between the total amount of data actually written to physical storage and the amount of data the application logically intended to write. Arises because a single logical write can end up being rewritten multiple times...
29. What is Read Amplification?
Read amplification is the ratio between the amount of data actually read from storage to answer a query and the amount of data logically needed to answer it. Happens because a single key lookup may need to check the MemTable...
30. What is Space Amplification?
Space amplification is the ratio between the actual disk space RocksDB's data files consume and the true logical size of the data currently stored. Occurs because outdated versions of a key, and tombstones marking deletions, can persist on disk until...
31. What is the purpose of Levels (L0 to Ln) in RocksDB's storage hierarchy?
RocksDB's leveled compaction organizes SSTables into a numbered hierarchy, from Level 0 up to a configurable maximum level, with each level generally holding more data than the one above it. Level 0 holds SSTables freshly flushed from MemTables, and their...
32. Describe the Write Path in RocksDB?
flowchart LR A[Put/Delete/Merge Call] --> B[Write to WAL on disk] B --> C[Write to Active MemTable in memory] C --> D{MemTable Full?} D -->|Yes| E[Mark Immutable, Flush to L0 SSTable] D -->|No| F[Await further writes] E --> G[Background Compaction] An...
33. Describe the Read Path in RocksDB?
flowchart LR A[Get key] --> B[Check Active MemTable] B --> C[Check Immutable MemTables] C --> D[Check L0 SSTables: Bloom filter + Index] D --> E[Check L1..Ln SSTables in order] E --> F[Return Value or Not Found] A Get call for...
34. What is an Immutable MemTable?
An Immutable MemTable is a MemTable that has reached its size limit and stopped accepting new writes, but hasn't yet been flushed to disk as an SSTable. Created the moment an active MemTable fills up, at which point a brand...
35. What is a Skip List?
A Skip List is a probabilistic data structure that maintains sorted data with multiple layers of "express lane" links, letting it support fast search, insertion, and deletion without the complexity of a balanced tree. The bottom layer contains every element...
36. What programming language is RocksDB written in?
RocksDB is written in C++, and its core is distributed as a native library that other software links directly into its own process. Being embeddable in C++ is what makes it usable as an internal storage engine inside other systems,...
37. What types of systems use RocksDB internally?
RocksDB is commonly used as the underlying storage engine inside larger, higher-level database and infrastructure systems, rather than being the end-user-facing database itself. Distributed SQL and NoSQL databases that need a fast, reliable local storage layer on each node Stream...
38. What is a Transaction in RocksDB?
RocksDB offers transaction support that lets multiple operations be grouped so they either all succeed together or none of them take effect, along with mechanisms to handle conflicting concurrent writes. Supports both optimistic and pessimistic concurrency control, letting an application...
39. What is Backup and Restore in RocksDB?
RocksDB includes built-in utilities for backing up a database's data to a separate location and later restoring it, without needing to write this logic from scratch. Backups can be taken incrementally, reusing unchanged SSTable files rather than copying the entire...
40. What is a Checkpoint in RocksDB?
A Checkpoint creates a lightweight, point-in-time copy of a RocksDB database, typically by hard-linking its current SSTable files rather than physically copying them. Extremely fast to create, since it mostly avoids duplicating the underlying immutable data files Produces a fully...
41. Describe how Compression is used in RocksDB?
RocksDB can compress the data blocks inside SSTables to reduce disk space usage and the amount of data that needs to be read from storage. Supports multiple compression algorithms, letting an operator choose a trade-off between compression ratio and CPU...
42. What is the purpose of a Data Block within an SSTable?
A Data Block is the actual unit of storage inside an SSTable that holds a contiguous, sorted group of key-value pairs. An SSTable is made up of many data blocks, each covering a small portion of that file's overall sorted...
43. What is Prefix Seek in RocksDB?
Prefix Seek is an iteration technique that lets RocksDB efficiently find and scan all keys sharing a common prefix, without needing to scan through unrelated keys. Relies on a configured prefix extractor, which tells RocksDB how to derive a prefix...
44. What is a Merge Operator in RocksDB?
A Merge Operator is custom logic an application supplies that defines how RocksDB should combine a base value with one or more pending Merge operations into a final result. Applied lazily, RocksDB doesn't necessarily compute the merged result immediately on...
45. List common configuration options that affect RocksDB performance?
MemTable size : a larger MemTable absorbs more writes before flushing, trading memory usage for fewer, larger flush operations Compaction style : leveled versus universal versus FIFO, each shifting the balance between write, read, and space amplification Block cache size...
46. What is a Sync Write versus an Async Write in RocksDB?
This distinction is about whether a write waits for its write-ahead log entry to be physically confirmed on durable storage before returning to the caller. Sync write : waits for the WAL entry to be flushed all the way to...
47. What is the purpose of the Options object in RocksDB's API?
The Options object is the central configuration structure passed when opening a RocksDB database, controlling nearly every tunable aspect of its behavior. Covers settings like MemTable size, compaction style, compression, block cache configuration, and the number of background threads Some...