RocksDB — Facebook's Embeddable Persistent Key-Value Store
A C++ LSM-tree storage engine from Meta powering MyRocks, CockroachDB, TiKV, Kafka Streams and more. Optimized for fast SSDs and workloads with high write throughput and low read latency.
What it is
RocksDB is a C++ embeddable persistent key-value store developed at Meta (Facebook). It uses an LSM-tree (Log-Structured Merge-tree) architecture optimized for fast storage devices like NVMe SSDs. RocksDB powers the storage layers of CockroachDB, TiKV, Kafka Streams, and MyRocks (MySQL with RocksDB backend).
RocksDB is for database engineers and systems developers who need an embedded storage engine with high write throughput, tunable read performance, and efficient compression.
The project is actively maintained with regular releases and a growing user community. Documentation covers common use cases, and the open-source nature means you can inspect the source code, contribute fixes, and adapt the tool to your specific requirements.
How it saves time or tokens
Building a production-quality storage engine from scratch takes years. RocksDB provides a battle-tested foundation with configurable compaction strategies, bloom filters, compression (LZ4, Zstd, Snappy), column families, and transaction support. Teams embed RocksDB instead of reinventing the storage layer.
How to use
- Install RocksDB from source or via package manager.
- Open a database instance with configured options (block cache, compaction style, compression).
- Use Put, Get, Delete, and Iterator operations for key-value access.
Example
#include <rocksdb/db.h>
#include <rocksdb/options.h>
int main() {
rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
options.compression = rocksdb::kLZ4Compression;
rocksdb::Status s = rocksdb::DB::Open(options, "/tmp/testdb", &db);
assert(s.ok());
// Write
db->Put(rocksdb::WriteOptions(), "key1", "value1");
// Read
std::string value;
db->Get(rocksdb::ReadOptions(), "key1", &value);
// value == "value1"
delete db;
return 0;
}
Related on TokRepo
- AI Tools for Database -- Database engines and storage tools
- AI Tools for DevOps -- Infrastructure and data platform tooling
Common pitfalls
- Default compaction settings are tuned for general workloads. Write-heavy workloads benefit from Level compaction, while space-sensitive workloads should use Universal compaction.
- RocksDB block cache size must be tuned to available memory. Setting it too small causes excessive disk reads; setting it too large starves the OS page cache.
- Write amplification is inherent to LSM-trees. Monitor compaction stats and tune
max_bytes_for_level_baseandlevel0_file_num_compaction_triggerto balance write amplification against read performance.
Before adopting this tool, evaluate whether it fits your team's existing workflow. Read the official documentation thoroughly, and start with a small proof-of-concept rather than a full migration. Community forums, GitHub issues, and Stack Overflow are valuable resources when you encounter edge cases not covered in the documentation.
Frequently Asked Questions
CockroachDB, TiKV (the storage engine for TiDB), Apache Kafka Streams, MyRocks (MySQL), and Apache Flink all use RocksDB as their underlying storage layer. It is one of the most widely embedded storage engines in production systems.
RocksDB is a fork of LevelDB with significant enhancements: multi-threaded compaction, column families, transactions, bloom filters per level, pluggable compression, and rate limiting. LevelDB is simpler but lacks these production features.
A Log-Structured Merge-tree writes data to an in-memory buffer (memtable), then flushes to sorted files on disk (SSTables). Background compaction merges and sorts these files. This design optimizes for write throughput at the cost of read amplification.
Yes. RocksDB provides both optimistic and pessimistic transaction support via the TransactionDB and OptimisticTransactionDB APIs. Transactions guarantee atomic writes across multiple keys with snapshot isolation.
RocksDB supports LZ4, Zstd, Snappy, zlib, and BZip2 compression. You can configure different compression algorithms per level of the LSM-tree to balance CPU usage against storage savings.
Citations (3)
- RocksDB GitHub— RocksDB is a persistent key-value store from Meta
- RocksDB Wiki— LSM-tree architecture with configurable compaction
- RocksDB Users— Used by CockroachDB, TiKV, and MyRocks
Related on TokRepo
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.