Convert Figma logo to code with AI

facebook logorocksdb

A library that provides an embeddable, persistent key-value store for fast storage.

28,450
6,298
28,450
1,048

Top Related Projects

36,378

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

4,766

RocksDB/LevelDB inspired key-value database in Go

FoundationDB - the open source, distributed, transactional key-value store

14,991

Distributed transactional key-value database, originally created to complement TiDB

5,214

Apache HBase

13,213

NoSQL data store using the seastar framework, compatible with Apache Cassandra

Quick Overview

RocksDB is a high-performance embedded database for key-value data. Developed by Facebook, it's optimized for fast, low-latency storage on flash drives and RAM. RocksDB is widely used in production environments for its ability to handle large-scale data with excellent read and write performance.

Pros

  • Exceptional performance for both read and write operations
  • Highly customizable with various compression and caching options
  • Supports atomic updates and consistent point-in-time backups
  • Active development and maintenance by Facebook and a large community

Cons

  • Steep learning curve due to numerous configuration options
  • Can be memory-intensive, especially with large datasets
  • Limited support for complex queries compared to full-fledged databases
  • Requires careful tuning for optimal performance in specific use cases

Code Examples

  1. Opening a database and performing basic operations:
#include <rocksdb/db.h>

rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status = rocksdb::DB::Open(options, "/path/to/db", &db);

// Write operation
db->Put(rocksdb::WriteOptions(), "key1", "value1");

// Read operation
std::string value;
status = db->Get(rocksdb::ReadOptions(), "key1", &value);

delete db;
  1. Using column families:
std::vector<rocksdb::ColumnFamilyDescriptor> column_families;
column_families.push_back(rocksdb::ColumnFamilyDescriptor(
    rocksdb::kDefaultColumnFamilyName, rocksdb::ColumnFamilyOptions()));
column_families.push_back(rocksdb::ColumnFamilyDescriptor(
    "new_cf", rocksdb::ColumnFamilyOptions()));

std::vector<rocksdb::ColumnFamilyHandle*> handles;
rocksdb::DB* db;
rocksdb::Status s = rocksdb::DB::Open(options, kDBPath, column_families, &handles, &db);
  1. Using transactions:
rocksdb::TransactionDB* txn_db;
rocksdb::TransactionDBOptions txn_db_options;
rocksdb::Options options;

rocksdb::Status status = rocksdb::TransactionDB::Open(options, txn_db_options, "/path/to/db", &txn_db);

rocksdb::Transaction* txn = txn_db->BeginTransaction(write_options);
txn->Put("key1", "value1");
txn->Merge("key2", "value2");
s = txn->Commit();

delete txn;
delete txn_db;

Getting Started

To use RocksDB in your C++ project:

  1. Install RocksDB:

    git clone https://github.com/facebook/rocksdb.git
    cd rocksdb
    make static_lib
    
  2. Include RocksDB in your project:

    #include <rocksdb/db.h>
    
  3. Compile with RocksDB:

    g++ -std=c++11 your_file.cpp -lrocksdb -ldl -lpthread
    
  4. Basic usage:

    rocksdb::DB* db;
    rocksdb::Options options;
    options.create_if_missing = true;
    rocksdb::Status status = rocksdb::DB::Open(options, "/path/to/db", &db);
    // Use db for operations
    delete db;
    

Competitor Comparisons

36,378

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

Pros of LevelDB

  • Simpler and more lightweight, making it easier to integrate and use in smaller projects
  • Lower memory footprint, suitable for resource-constrained environments
  • Faster for small datasets and simple key-value operations

Cons of LevelDB

  • Limited features compared to RocksDB, lacking advanced functionalities like column families and transactions
  • Less actively maintained, with fewer updates and improvements
  • Not as well-suited for high-concurrency scenarios or large-scale applications

Code Comparison

LevelDB:

leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);

RocksDB:

rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status = rocksdb::DB::Open(options, "/tmp/testdb", &db);

Both libraries share similar APIs, making it relatively easy to switch between them. However, RocksDB offers more advanced options and configurations for fine-tuning performance and behavior.

RocksDB, being a fork of LevelDB, builds upon its foundation and extends its capabilities. While LevelDB is suitable for simpler use cases and smaller projects, RocksDB is better equipped for handling larger datasets, higher concurrency, and more complex scenarios in production environments.

4,766

RocksDB/LevelDB inspired key-value database in Go

Pros of Pebble

  • Designed specifically for distributed systems, optimized for CockroachDB's use case
  • Simpler codebase, easier to maintain and extend
  • Better performance for certain workloads, particularly those involving range deletions

Cons of Pebble

  • Less mature and battle-tested compared to RocksDB
  • Smaller community and ecosystem support
  • May lack some advanced features present in RocksDB

Code Comparison

RocksDB (C++):

rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status = rocksdb::DB::Open(options, "/tmp/testdb", &db);

Pebble (Go):

db, err := pebble.Open("/tmp/testdb", &pebble.Options{})
if err != nil {
    log.Fatal(err)
}
defer db.Close()

Both RocksDB and Pebble are key-value storage engines, but they have different design goals and target use cases. RocksDB is a more general-purpose storage engine with a wide range of applications, while Pebble is tailored for distributed systems, particularly CockroachDB.

RocksDB offers a broader feature set and has been extensively used in production environments. Pebble, on the other hand, focuses on simplicity and performance optimizations for specific workloads.

The code comparison shows that both libraries provide similar basic functionality for opening a database, but with different syntax due to their respective programming languages (C++ for RocksDB and Go for Pebble).

FoundationDB - the open source, distributed, transactional key-value store

Pros of FoundationDB

  • Distributed architecture with strong ACID guarantees
  • Multi-model database supporting key-value, document, and relational models
  • Built-in fault tolerance and automatic data distribution

Cons of FoundationDB

  • Steeper learning curve due to its unique architecture
  • Limited language bindings compared to RocksDB
  • Smaller community and ecosystem

Code Comparison

RocksDB (C++):

rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status = rocksdb::DB::Open(options, "/path/to/db", &db);

FoundationDB (Python):

import fdb
fdb.api_version(630)
db = fdb.open()
@fdb.transactional
def set_value(tr, key, value):
    tr[key] = value

RocksDB is a high-performance embedded key-value store, while FoundationDB is a distributed database designed for scalability and consistency. RocksDB offers fine-grained control over storage engine behavior, making it suitable for custom storage solutions. FoundationDB provides a more comprehensive distributed system out-of-the-box, with strong consistency guarantees.

RocksDB has a larger ecosystem and wider adoption, particularly in the open-source community. FoundationDB, while powerful, has a smaller community and fewer language bindings. Both databases have their strengths, and the choice between them depends on specific project requirements, such as scalability needs, consistency guarantees, and integration complexity.

14,991

Distributed transactional key-value database, originally created to complement TiDB

Pros of TiKV

  • Distributed key-value store with strong consistency and high availability
  • Supports ACID transactions across multiple keys
  • Designed for horizontal scalability and cloud-native deployments

Cons of TiKV

  • Higher complexity due to distributed nature
  • Potentially higher latency for single-node operations
  • Steeper learning curve for implementation and maintenance

Code Comparison

RocksDB (C++):

rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status = rocksdb::DB::Open(options, "/tmp/testdb", &db);

TiKV (Rust):

let config = Config::default();
let pd_client = RpcClient::new(&config).unwrap();
let cluster_id = pd_client.get_cluster_id().unwrap();
let store_id = pd_client.alloc_id().unwrap();
let mut node = Node::new(config, pd_client, store_id);

Summary

RocksDB is a high-performance embedded key-value store, while TiKV is a distributed key-value database built on top of RocksDB. TiKV offers additional features like distributed transactions and horizontal scalability, but comes with increased complexity. RocksDB is simpler to implement and may have lower latency for single-node operations, but lacks built-in distributed capabilities. The choice between the two depends on specific project requirements, such as scalability needs and consistency guarantees.

5,214

Apache HBase

Pros of HBase

  • Designed for distributed storage and processing of large datasets
  • Supports real-time read/write access to big data
  • Integrates well with Hadoop ecosystem

Cons of HBase

  • Higher complexity and steeper learning curve
  • Requires more system resources and maintenance
  • Less suitable for smaller-scale applications

Code Comparison

HBase (Java):

Put put = new Put(Bytes.toBytes("row1"));
put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"), Bytes.toBytes("value1"));
table.put(put);

RocksDB (C++):

rocksdb::WriteOptions write_options;
db->Put(write_options, "key", "value");

Key Differences

  • HBase is a distributed, column-oriented database built on HDFS, while RocksDB is an embedded key-value store
  • HBase is better suited for large-scale distributed systems, while RocksDB excels in performance for smaller datasets
  • HBase offers more complex querying capabilities, while RocksDB focuses on simple key-value operations
  • RocksDB provides lower latency and higher throughput for single-node deployments
  • HBase has a more extensive feature set for distributed computing and data management
13,213

NoSQL data store using the seastar framework, compatible with Apache Cassandra

Pros of ScyllaDB

  • Designed for high-performance, low-latency distributed database operations
  • Implements a shared-nothing architecture for better scalability
  • Optimized for modern multi-core processors and SSDs

Cons of ScyllaDB

  • More complex setup and configuration compared to RocksDB
  • Steeper learning curve for developers new to distributed systems
  • Limited ecosystem and third-party tool support compared to RocksDB

Code Comparison

ScyllaDB (C++):

class sstable {
    std::unique_ptr<index_reader> _index;
    std::unique_ptr<compression> _compression;
    file _data_file;
    uint64_t _data_file_size;
    // ...
};

RocksDB (C++):

class SSTableReader : public TableReader {
 private:
  Status ReadMetaBlock(std::unique_ptr<Block>* meta_block);
  BlockBasedTable* table_;
  RandomAccessFileReader* file_;
  // ...
};

Both projects use C++ and focus on efficient storage and retrieval of data. ScyllaDB's code emphasizes distributed systems and network-oriented operations, while RocksDB's code is more focused on local storage optimization and file I/O operations. ScyllaDB's implementation includes more components related to distributed computing, while RocksDB's code is more centered around block-based storage and file management.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

RocksDB: A Persistent Key-Value Store for Flash and RAM Storage

CircleCI Status

RocksDB is developed and maintained by Facebook Database Engineering Team. It is built on earlier work on LevelDB by Sanjay Ghemawat (sanjay@google.com) and Jeff Dean (jeff@google.com)

This code is a library that forms the core building block for a fast key-value server, especially suited for storing data on flash drives. It has a Log-Structured-Merge-Database (LSM) design with flexible tradeoffs between Write-Amplification-Factor (WAF), Read-Amplification-Factor (RAF) and Space-Amplification-Factor (SAF). It has multi-threaded compactions, making it especially suitable for storing multiple terabytes of data in a single database.

Start with example usage here: https://github.com/facebook/rocksdb/tree/main/examples

See the github wiki for more explanation.

The public interface is in include/. Callers should not include or rely on the details of any other header files in this package. Those internal APIs may be changed without warning.

Questions and discussions are welcome on the RocksDB Developers Public Facebook group and email list on Google Groups.

License

RocksDB is dual-licensed under both the GPLv2 (found in the COPYING file in the root directory) and Apache 2.0 License (found in the LICENSE.Apache file in the root directory). You may select, at your option, one of the above-listed licenses.