Badger started as a key-value store, so the goal was to use the latest research to build a key-value store. It uses a log-structured merge (LSM) tree based implementation, which has an advantage in throughput when compared to B+ tree since background (disk) writes in LSM maintain a sequential access pattern.[03]
- Source Code
- https://github.com/dgraph-io/badger[01]
- Developer
- Country of Origin
- US
- Start Year
- 2017 [10]
- Project Type
- Open Source
- Written in
- Go
- Derived From
- DGraph
- Inspired By
- RocksDB
- Compatible With
- DGraph
- License
- Apache v2
Badger started as a key-value store, so the goal was to use the latest research to build a key-value store. It uses a log-structured merge (LSM) tree based implementation, which has an advantage in throughput when compared to B+ tree since background (disk) writes in LSM maintain a sequential access pattern.[03]
History[04][03][05]
BadgerDB was initially a persistent key-value store intended to replace DgraphDB’s dependency on RocksDB, since RocksDB is written in C++ and requires the use of Cgo to be called via Go. It was a (side) project lead by Manish Rai Jain, a chief decision maker at Dgraph.
As the project progressed, in 2017 the developers decided to expand the scope of the project to be a more full-featured database system.
Checkpoints[06]
The user has the option to determine whether changes are immediately propagated to disk after an update. If this option is disabled, then writes may not sync to disk immediately. All writes will be flushed to disk when the application closes the database. In addition to changes being propagate to disk when the application closes the database, changes are also propagated when a max table size threshold (MaxTableSize) is reached.
Compression[03][07]
BadgerDB uses delta encoding to reduce the size of keys, to further reduce the size of the LSMs. Also, during a read, a fingerprint of the key is stored rather than the key itself to also save space. The fingerprint of a key contains the information necessary to identify a unique key, but takes up less space. It is not a 100% accurate and can cause a false negative causing a transaction to abort (and requiring it to be restarted).
Concurrency Control[01][07]
Badger supports ACID transactions and Multi-Version Concurrency Control with Snapshot Isolation. Badger acquires locks on directories when accessing data, so multiple processes cannot open the same database at the same time. If the transaction is read-write, the transaction checks if there is a conflict and return and error if there is one.
Data Model[06][05]
Badger’s underlying functionality is a key-value store. The user can choose to store additional meta-data with the key-value pair for use when processing that data.
Indexes[03]
BadgerDB supports a LSM tree, where keys are stored in the LSM and values are store in a write-ahead log called a value log. Since key tend to be smaller than values, this allows the system to maintain a smaller LSM tree. The LSM make sure to maintain a sorted order, making range queries easier to process, as well.
Isolation Levels[05][07]
BadgerDB supports snapshot isolation. Badger also has read-only transactions (called Views), that ensures a consistent view of the database system, and that will not include changes made by an uncommitted transaction at the start of this transactions. With read-write transactions, if a conflict occurs, the transaction will written with an error notifying the user of a conflict, giving the user the option to retry the transaction.
Query Execution[06][09][03]
BadgerDB is inspired by the simplicity of LevelDB and supports Get, Set, Delete, and Iterate functions. Multiple updates can be batched-up into a single transaction, allowing the user to do a lot of writes at a time.
Query Interface[03][05][02]
The query interface for BadgerDB is in Go since the system was originally created to provide a key-value store that can easily be accessed through Go without having to go through Ggo.
Storage Architecture[06][03][01][08]
BadgerDB is an in-memory DBMS, that supports larger-than-memory databases by writing to disk. Disk is also used to make the BadgerDB persistent and resilient. BadterDB works in-memory until the MaxTableSize threshold is reached, at which point the data is propagated to disk.
Storage Model[03]
The LSM writes the initial in-memory updates in memtables. Once those are full, they are moved over to immutable memtables that are eventually written to disk.
Storage Organization[03]
Badger uses LSMs, which were designed around hard drives, since random I/Os are slower than sequential ones, and LSMs allow for sequential background read/writes rather than random ones.
Citations
11 sources- GitHub - dgraph-io/badger: Fast key-value DB in Go. · GitHub github.com
- badger package - github.com/dgraph-io/badger - Go Packages godoc.org
- https://blog.dgraph.io/post/badger/ dgraph.io
- History for README.md - dgraph-io/badger · GitHub github.com
- badger/README.md at master · dgraph-io/badger · GitHub github.com
- badger package - github.com/dgraph-io/badger - Go Packages godoc.org
- https://blog.dgraph.io/post/badger-txn/ dgraph.io
- https://blog.dgraph.io/post/alice/ dgraph.io
- Create a WriteBatch API to allow efficient serial writes (#608) **Breaking change** - This change removes the ability to provide a callback in Commit. Instead, it creates another function called CommitWith, which takes a callback. - Previously, a u github.com
- badger/CHANGELOG.md at master · dgraph-io/badger · GitHub github.com
- https://github.com/dgraph-io/badger/commit/abbb9a574e03c36e13f5f0fa62c74504c5e9ee05 github.com