Badger DB Star

Fast, Embeddable, and Open Source.
The Most Popular, Actively Developed Go Key-Value Store.

Copy
  • func
    main()
    {
  • // Open the Badger database located in the /tmp/badger directory.
  • // It will be created if it doesn't exist.
  • db, err
    :=
    badger
    .Open
    (badger
    .DefaultOptions
    ("/tmp/badger"))
  • if
    err
    != nil
    {
  • log
    .Fatal
    (err)
  • }
  • defer
    db
    .Close()
  • // Your code here...
  • }

Used by Popular Projects Such As

See the complete list here .


The Only Key-Value Store You'll Ever Need

Built for performance, Badger is everything you are looking for in a Key-Value store.

FAST

Insert data at the speed of 160 MB/s

CRASH RESILIENT

The Write Ahead Log ensures your data is safe and sound

OPTIMIZED FOR SSD

Separation of Key-Value enables faster reads

LOADED WITH BATTERIES

Supports Compression, Encryption, TTL and more


Badger is Easy To Use

Step 1. Open a new Badger instance

Copy
func
main() {
// Open the Badger database located in the /tmp/badger directory.
// It will be created if it doesn't exist.
db, err
:=
badger
.Open
(badger
.DefaultOptions
("/tmp/badger"))
if
err
!= nil
{
log
.Fatal
(err)
}
defer
db
.Close()
}

Step 2. Create a read-write transaction

Copy
err
:=
db.Update(
func
(txn
*
badger.Txn) error {
// Your code here.
return
nil
})

Step 3. Insert a key using the Set operation

Copy
err
:=
db.Update(
func
(txn
*
badger.Txn) error {
return
txn
.Set
([]byte("answer"), []byte("
42
"))
})

Step 4. Fetch the inserted key using the Get operation

Copy
err
:=
db.View(
func
(txn
*
badger.Txn) error {
item, err
:=
txn
.Get
([]byte("answer"))
// Use item here.
})

Why Choose Badger?

Speed

Speed, Speed, and More Speed

Badger was built for performance. Writing data at the speed of 160 MB/s and reading it at 80 MB/s, Badger is the fastest LSM Tree-based Key-Value Store written in Go.

Transaction

Transaction and Data Guarantees

Badger supports concurrent ACID transactions with serializable snapshot isolation (SSI) guarantees. The Write Ahead Log ensures you never lose data.

Stream

Stream Framework and Managed Mode

Building systems on top of Badger is easy with the Stream framework which allows bulk reading and writing of data by leveraging the power of Goroutines. The managed mode allows systems to take control of the transactions while Badger takes care of everything else.

Batteriy

Batteries Included

A LRU Cache and support for Compression, Encryption, Time To Live (TTL), Badger comes with everything that you need from a Key-Value store.


Want to Learn More About Badger?

Introducing Badger: A fast key-value store written purely in Go

Blog post

Read More

Why we choose Badger over RocksDB in Dgraph

Blog post

Read More

KV Database: Badger Talk at GoSF Meetup

Video

Watch Video

Ready to get started?

TRY BADGER NOW