Prev Next

Database / RocksDB Basics Interview Questions

1. What is RocksDB? 2. Who developed RocksDB? 3. What is RocksDB based on? 4. What is a Key-Value Store? 5. Define the LSM-Tree (Log-Structured Merge-Tree)? 6. What is a MemTable in RocksDB? 7. What data structure implements RocksDB's default MemTable? 8. What is a Write-Ahead Log (WAL) in RocksDB? 9. What is an SSTable in RocksDB? 10. What is Flushing in RocksDB? 11. What is Compaction in RocksDB? 12. What are the Compaction Styles supported by RocksDB? 13. Define Leveled Compaction? 14. Define Universal Compaction? 15. What is a Bloom Filter in RocksDB? 16. What is an Index Block in an SSTable? 17. What is a Block Cache in RocksDB? 18. What is the Manifest file in RocksDB? 19. What are Column Families in RocksDB? 20. What is a Comparator in RocksDB? 21. What is a Snapshot in RocksDB? 22. What is an Iterator in RocksDB? 23. What is the purpose of the Put operation in RocksDB? 24. What is the purpose of the Get operation in RocksDB? 25. What is the purpose of the Delete operation in RocksDB? 26. What is a Tombstone in RocksDB? 27. What is Merge in RocksDB? 28. What is Write Amplification? 29. What is Read Amplification? 30. What is Space Amplification? 31. What is the purpose of Levels (L0 to Ln) in RocksDB's storage hierarchy? 32. Describe the Write Path in RocksDB? 33. Describe the Read Path in RocksDB? 34. What is an Immutable MemTable? 35. What is a Skip List? 36. What programming language is RocksDB written in? 37. What types of systems use RocksDB internally? 38. What is a Transaction in RocksDB? 39. What is Backup and Restore in RocksDB? 40. What is a Checkpoint in RocksDB? 41. Describe how Compression is used in RocksDB? 42. What is the purpose of a Data Block within an SSTable? 43. What is Prefix Seek in RocksDB? 44. What is a Merge Operator in RocksDB? 45. List common configuration options that affect RocksDB performance? 46. What is a Sync Write versus an Async Write in RocksDB? 47. What is the purpose of the Options object in RocksDB's API?

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 merge-tree (LSM-tree) Runs inside ...

Read full answer

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 original creator Activ...

Read full answer

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, ...

Read full answer

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 under a key, retrieving a value by its key, and deleting a key ...

Read full answer

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 being written directly to their final location on disk Th...

Read full answer

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 directly into a sorted file later Has a configurable maximum siz...

Read full answer

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 flushed directly into an already-sorte...

Read full answer

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 replayed to recover those writes Written sequentially, which...

Read full answer

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 SSTable is never modified in place, only replaced...

Read full answer

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 over for future writes A background thread performs th...

Read full answer

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 removes dat...

Read full answer

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 by recency and peri...

Read full answer

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 Level 1 onward, SSTables within a level cover non-o...

Read full answer

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 one Tends to produce lower write a...

Read full answer

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 be present when it isn't, but never false negat...

Read full answer

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 for the data blocks inside that SSTable Loaded into memory, often ca...

Read full answer

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 on every lookup Configurable in size, letting operat...

Read full answer

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 during startup to reconstruct exactly what ...

Read full answer

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 share the same u...

Read full answer

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 differently, for example tr...

Read full answer

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, even while other writes continue concurrently Doesn't physically c...

Read full answer

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 backward through the sorted keyspace Transparently merges data from the MemTable and...

Read full answer

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 key already exists, its previous value is logically superseded by the new one, though t...

Read full answer

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 filters and index blocks along the way to avoid unne...

Read full answer

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 away The tombstone is what later reads use to ...

Read full answer

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 a Put would Causes reads for that key to correctly report it as not fou...

Read full answer

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 whole thing Requires the application to supply a Merge ...

Read full answer

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 as it moves through compaction across levels H...

Read full answer

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 and multiple SSTables across several levels before finding, or ruling ou...

Read full answer

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 compaction removes them Compaction styles that...

Read full answer

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 key ranges can overlap each other Level 1...

Read full answer

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 application calls Put, Delete, or Merge with ...

Read full answer

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 a key first checks the active MemTable, since that holds the most rece...

Read full answer

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 new, empty MemTable takes over for future writes Still readable, so Get c...

Read full answer

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 in sorted order, like a regular linked ...

Read full answer

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, rather than a standalone server application Official bindings and...

Read full answer

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 processing and m...

Read full answer

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 choose t...

Read full answer

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 database every time Because SSTa...

Read full answer

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 independent, ope...

Read full answer

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 cost Can be configured differently per leve...

Read full answer

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 key range The SSTable's index block records where each data block starts, l...

Read full answer

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 from a full key Can use a specialized prefix Bloo...

Read full answer

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 every write, only when a read or compac...

Read full answer

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 : a larger cache keeps mo...

Read full answer

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 physical storage before the write call returns, guaranteeing durability eve...

Read full answer

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 settin...

Read full answer

«
»

Comments & Discussions