redb

October 17, 2025 ยท View on GitHub

CI Crates.io Documentation License dependency status

A simple, portable, high-performance, ACID, embedded key-value store.

redb is written in pure Rust and is loosely inspired by lmdb. Data is stored in a collection of copy-on-write B-trees. For more details, see the design doc

use redb::{Database, Error, ReadableDatabase, TableDefinition};

const TABLE: TableDefinition<&str, u64> = TableDefinition::new("my_data");

fn main() -> Result<(), Error> {
    let db = Database::create("my_db.redb")?;
    let write_txn = db.begin_write()?;
    {
        let mut table = write_txn.open_table(TABLE)?;
        table.insert("my_key", &123)?;
    }
    write_txn.commit()?;

    let read_txn = db.begin_read()?;
    let table = read_txn.open_table(TABLE)?;
    assert_eq!(table.get("my_key")?.unwrap().value(), 123);

    Ok(())
}

Status

Stable and maintained.

The file format is stable, and a reasonable effort will be made to provide an upgrade path if there are any future changes to it.

Features

  • Zero-copy, thread-safe, BTreeMap based API
  • Fully ACID-compliant transactions
  • MVCC support for concurrent readers & writer, without blocking
  • Crash-safe by default
  • Savepoints and rollbacks

Development

To run all the tests and benchmarks a few extra dependencies are required:

  • cargo install cargo-deny --locked
  • cargo install cargo-fuzz --locked
  • apt install libclang-dev

Benchmarks

redb has similar performance to other top embedded key-value stores such as lmdb and rocksdb

redblmdbrocksdbsledfjallsqlite
bulk load17063ms9232ms13969ms24971ms18619ms15341ms
individual writes920ms1598ms2432ms2701ms3488ms7040ms
batch writes1595ms942ms451ms853ms353ms2625ms
len()0ms0ms749ms1573ms1181ms30ms
random reads1138ms637ms2911ms1601ms2177ms4283ms
random reads934ms631ms2884ms1592ms2357ms4281ms
random range reads1174ms565ms2734ms1992ms2564ms8431ms
random range reads1173ms565ms2742ms1993ms2690ms8449ms
random reads (4 threads)1390ms840ms3995ms1913ms2606ms7000ms
random reads (8 threads)757ms427ms2147ms1019ms1352ms8123ms
random reads (16 threads)652ms216ms1478ms690ms963ms23022ms
random reads (32 threads)410ms125ms1100ms444ms576ms26536ms
removals23297ms10435ms6900ms11088ms6004ms10323ms
uncompacted size4.00 GiB2.61 GiB893.18 MiB2.13 GiB1000.95 MiB1.09 GiB
compacted size1.69 GiB1.26 GiB454.71 MiBN/A1000.95 MiB556.85 MiB

Source code for benchmark here. Results collected on a Ryzen 9950X3D with Samsung 9100 PRO NVMe.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.