cdb
activeby D. J. Bernstein · since 1996 · also known as constant database, cdb64
D. J. Bernstein's constant database: immutable on-disk hash tables with two-read lookups and atomic swaps.
Overview
cdb is a small C library and file format by D. J. Bernstein for constant databases: a key/value file is built once with cdbmake and afterwards only read. A fixed header points into 256 hash tables, so a successful lookup normally needs two disk reads and a miss only one; readers need no locks, and a replacement database is written to a temporary file and renamed into place, so readers never see a half-built file and crashes cannot corrupt it. It was written for qmail, djbdns and ucspi-tcp and has been reimplemented in most languages. After decades at version 0.75, Bernstein published a new release in October 2025 that adds cdb64, lifting the classic 4 GB file limit. It suits read-mostly lookup tables that are rebuilt in batches.
Strengths & trade-offs
Strengths
- +Successful lookups usually cost two disk reads, misses one
- +Lock-free concurrent readers and crash-safe atomic replacement via rename
- +Machine-independent format with implementations in most languages
- +Public-domain code small enough to audit in an afternoon
- +cdb64 (2025) removes the 4 GB size ceiling
Trade-offs
- −No in-place updates: every change rebuilds the whole file
- −Exact-key lookups only; no range scans or secondary indexes
- −Classic format is limited to 4 GB
Great for
- +Mail and DNS server lookup tables
- +Read-only configuration or routing maps rebuilt in batches
- +Static key/value datasets shipped with an application
Think twice for
- −Frequently updated data
- −Range or prefix queries
- −Multi-key transactions
Capabilities
Native or official first-party support · 1 of 25 tracked
Scale & consistency
- Comfortable data size
- Small · ≤ 100 GB
- Horizontal scaling
- None
- Multi-region
- No
- Transactions
- Limited ACID
- Consistency
- Strong
- Schema
- Schemaless
- Architecture
- Embedded
- Query languages
- C API
Classic cdb files are limited to 4 GB; cdb64 raises the limit to exabytes. Any change means rebuilding the file.
Deployment
Ecosystem
Alternatives to cdb
Tiny memory-mapped B+tree with ACID transactions and lock-free readers; reached 1.0 in 2026.
cdb vs lmdb →Google's original small, fast LSM key-value library, now in limited-maintenance mode.
cdb vs leveldb →Meta's embeddable LSM-tree key-value engine, the storage layer under dozens of databases.
cdb vs rocksdb →The 1990s-era embedded key-value library, now Oracle-owned, AGPL-licensed and rarely updated.
cdb vs berkeley-db →The in-process SQL engine that ships in every phone, browser and OS: one file, zero servers.
cdb vs sqlite →etcd's maintained fork of BoltDB: a simple, pure-Go B+tree store in a single file.
cdb vs bbolt →cdb FAQ
What is cdb?
cdb is a key-value database by D. J. Bernstein, first released in 1996. cdb is a small C library and file format by D. J. Bernstein for constant databases: a key/value file is built once with cdbmake and afterwards only read. A fixed header points into 256 hash tables, so a successful lookup normally needs two disk reads and a miss only one; readers need no locks, and a replacement database is written to a temporary file and renamed into place, so readers never see a half-built file and crashes cannot corrupt it. It was written for qmail, djbdns and ucspi-tcp and has been reimplemented in most languages. After decades at version 0.75, Bernstein published a new release in October 2025 that adds cdb64, lifting the classic 4 GB file limit. It suits read-mostly lookup tables that are rebuilt in batches.
Is cdb open source?
Yes. cdb is open source. License: Public domain.
Does cdb support ACID transactions?
Partly. cdb offers limited ACID guarantees (for example, single-record or single-partition transactions), with strong consistency.
Does cdb scale horizontally?
cdb does not scale horizontally; it runs on a single node, so you scale it up rather than out. It is comfortable at small scale (≤ 100 GB).
How can I run cdb?
You can self-host it and embed it in your application.
What is cdb best for?
cdb is a strong fit for mail and DNS server lookup tables; read-only configuration or routing maps rebuilt in batches; and static key/value datasets shipped with an application. Think twice for frequently updated data.
What are the best alternatives to cdb?
Common alternatives to cdb include LMDB, LevelDB, RocksDB, Oracle Berkeley DB and SQLite. The right choice depends on your workload, scale and hosting; WhichDB's smart match ranks them against your requirements.
How popular is cdb?
cdb ranks #434 of 844 databases on the WhichDB Score (3.5/100), and #65 among key-value databases. The score combines public adoption signals such as package downloads, GitHub activity, job posts and developer discussion.