How dgraph-io/badger works
BadgerDB is an embeddable Go key-value database. Applications open a DB, read and write through transactions, and retrieve ordered or versioned results with iterators; the documented storage design separates values into a value log and maintains keys in an LSM tree. The repository also provides streaming and offline backup/restore capabilities. The tree and README establish these product areas, but the sampled source is incomplete, so uncertain internal call wiring is omitted.
Main entry points: txn.go Transactions · levels.go LSM levels · compaction.go Compaction · root.go Admin CLI
Components 20
Database API
- DB lifecycle
db.go - Transactions
txn.go - Write batches
batch.go - KV iterators
iterator.go - Stream API
stream.go - DB options
options.go
Storage Engine
- Memtables
memtable.go - Value log
value.go - LSM levels
levels.go - Level tables
level_handler.go - Sorted tables
table/table.go - Compaction
compaction.go - Manifest
manifest.go
Maintenance and Tools
- Backup and restore
backup.go - Admin CLI
badger/cmd/root.go - Backup command
badger/cmd/backup.go - Restore command
badger/cmd/restore.go
Internal Structures
- Skip lists
skl/skl.go - Value encoding
structs.go
Other components
- Application
Connections 19
- Application → DB lifecycle: opens DB
- Application → Transactions: starts transactions
- Application → KV iterators: iterates keys
- Application → Stream API: uses streaming
- DB lifecycle → DB options: uses options
- Transactions → Memtables: writes keys
- Transactions → Value log: stores values
- Transactions → LSM levels: reads keys
- KV iterators → LSM levels: scans keys
- LSM levels → Level tables: manages levels
- Level tables → Sorted tables: reads tables
- Compaction → Sorted tables: rewrites tables
- Compaction → Manifest: records changes
- Memtables → Skip lists: indexes entries
- Transactions → Value encoding: encodes values
- Admin CLI → Backup command: dispatches
- Admin CLI → Restore command: dispatches
- Backup command → Backup and restore: creates backup
- Restore command → Backup and restore: restores data