explaingit

cberner/redb

4,490RustAudience · developerComplexity · 3/5LicenseSetup · moderate

TLDR

redb is an embedded key-value database for Rust apps, no server needed, just add it as a dependency and store data in a single file on disk, with crash safety, typed tables checked at compile time, and concurrent readers built in.

Mindmap

mindmap
  root((redb))
    What it does
      Embedded key-value store
      No separate server
    Design
      B-plus tree storage
      ACID transactions
      MVCC readers
    Features
      Typed tables
      Savepoints and rollback
      Single file on disk
    Compared to
      lmdb
      rocksdb
      SQLite
    License
      MIT or Apache 2
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add a local persistent key-value store to a Rust CLI tool or desktop app without running a separate database server.

USE CASE 2

Store typed key-value data that survives a program crash, with ACID transactions ensuring nothing is half-written.

USE CASE 3

Handle multiple concurrent readers without blocking writes in a Rust application that needs high read throughput.

USE CASE 4

Replace SQLite in a Rust app when you only need key-value storage and want compile-time type checking on table keys and values.

Tech stack

Rust

Getting it running

Difficulty · moderate Time to first run · 30min

Add as a Cargo dependency, no external dependencies or server processes required.

MIT or Apache 2.0, your choice, use freely in any project, open source or commercial, with no significant restrictions.

In plain English

redb is a database library written in Rust that you embed directly into your application. An embedded database means there is no separate database server to install or manage. Your program links to redb and uses it to store and retrieve data, all within the same process. The data lives in a single file on disk. The core storage model uses a B+ tree (a data structure commonly used in databases). Data is stored as key-value pairs, meaning every piece of information has a unique key and an associated value, like entries in a dictionary. The library is ACID-compliant, which means each transaction either fully succeeds or fully fails, data written to disk survives a crash, and concurrent access from multiple threads is handled safely. A notable design choice is MVCC, which stands for multi-version concurrency control. This lets multiple readers operate at the same time without blocking the writer, and without the writer blocking the readers. Each reader sees a consistent point-in-time snapshot of the data. The library also supports savepoints and rollbacks within a transaction, letting you undo partial work before committing. The README includes a short code example: create a database file, define a typed table, open a write transaction, insert a key-value pair, commit, then open a read transaction and retrieve the value. Tables are typed at compile time, so the Rust compiler checks that keys and values match the declared types. Benchmarks in the README compare redb against other embedded databases including lmdb, rocksdb, sled, fjall, and SQLite. redb is fastest at individual writes and competitive across most other workloads. lmdb is faster for bulk loads and random reads. rocksdb produces the most compact on-disk files. The file format is described as stable, meaning data stored by current versions will continue to work with future releases. The library is available under your choice of MIT or Apache 2.0 license.

Copy-paste prompts

Prompt 1
Show me a complete Rust example using redb: create a database file, define a typed table with string keys and u64 values, insert three entries in a write transaction, commit, then read them back in a read transaction.
Prompt 2
I need an embedded database in my Rust app for caching. Compare redb, lmdb, and SQLite for this use case, which should I pick for mostly read workloads based on the benchmark results?
Prompt 3
Explain how redb's MVCC model lets multiple threads read concurrently while a write transaction is active, and show me Rust code that demonstrates two reader threads and one writer running at the same time.
Open on GitHub → Explain another repo

← cberner on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.