explaingit

dgraph-io/badger

15,612GoAudience · developerComplexity · 3/5Setup · easy

TLDR

BadgerDB is a fast, embeddable key-value database written in pure Go that you import as a library, no separate server to run, giving your Go program persistent local disk storage with SSD-optimized throughput.

Mindmap

mindmap
  root((BadgerDB))
    What It Is
      Embedded key-value DB
      Pure Go library
      No separate server
    Design
      LSM tree plus value log
      SSD optimized
      WiscKey research
    Features
      ACID transactions
      TTL key expiry
      Multiple key versions
    Use Cases
      Go app storage
      High-throughput cache
      Distributed systems
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 fast persistent key-value storage inside a Go application without running a separate database server process.

USE CASE 2

Store and retrieve terabytes of data on SSDs with high read and write throughput using concurrent ACID transactions.

USE CASE 3

Build a self-expiring cache or session store in Go using BadgerDB's built-in time-to-live key expiry feature.

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 30min

In plain English

BadgerDB is an embeddable, persistent key-value database written in pure Go. A key-value store maps unique names to chunks of data, like a dictionary that survives restarts. Because it is embeddable, you do not run it as a separate server, you import it as a library directly into your Go program and it stores data on the local disk. Badger is the underlying storage engine for Dgraph, a distributed graph database, and was created as a faster Go-native alternative to non-Go stores like RocksDB. Internally, Badger uses an LSM tree with a value log, based on the WiscKey research paper that separates keys from values to reduce write amplification on solid-state drives. Because of this design, Badger is specifically tuned for SSDs and aims for high throughput on both reads and writes, even on data sets in the terabytes range. It supports concurrent ACID transactions with serializable snapshot isolation, meaning many parts of your program can read and write at the same time without corrupting each other's view of the data. Other features include snapshots, time-to-live expiry on keys, and access to multiple versions of the same key. A nightly Jepsen-style bank test, run for hours with race detection on, exercises these transactional guarantees. You would reach for Badger when you need fast embedded storage inside a Go application and do not want the overhead of running a separate database process. Existing users include Dgraph, the Jaeger tracing platform, go-ipfs, and several distributed search and messaging projects. Installation is through go get, and a command-line tool is included for offline backup and restore. The full README is longer than what was provided.

Copy-paste prompts

Prompt 1
Write a Go program that uses BadgerDB to store and retrieve user session tokens with a 24-hour TTL, including a background goroutine that calls RunValueLogGC periodically.
Prompt 2
Using BadgerDB in Go, write a function that iterates over all key-value pairs with a given prefix and returns them as a map[string]string.
Prompt 3
Show me how to wrap two BadgerDB writes in a single ACID transaction in Go so both succeed or both roll back if one fails.
Prompt 4
What is the difference between BadgerDB and RocksDB, and when would I choose BadgerDB for an embedded Go application?
Prompt 5
How do I use the BadgerDB command-line tool to take an offline backup of a database and restore it on a different machine?
Open on GitHub → Explain another repo

← dgraph-io on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.