Lux Docs
Zapdb

Configuration

Database options, encryption, and storage backends

Default Options

opts := badger.DefaultOptions("/path/to/data")

This provides sensible defaults for most use cases. Override individual fields as needed.

Key Options

OptionDefaultDescription
Dir(required)Directory for LSM tree (keys + metadata)
ValueDirsame as DirDirectory for value log (can be separate SSD)
MemTableSize64MBSize of each in-memory table
NumMemtables5Number of memtables to keep
NumLevelZeroTables5Tables in level 0 before compaction
ValueLogFileSize1GBSize of each value log file
ValueThreshold1MBValues larger than this go to value log
NumCompactors4Number of concurrent compaction goroutines
CompressionSnappyCompression algorithm (None, Snappy, ZSTD)
DetectConflictstrueEnable transaction conflict detection

Encryption at Rest

opts := badger.DefaultOptions("/path/to/data")

// 16 or 32 byte key for AES-128 or AES-256
encryptionKey := []byte("0123456789abcdef0123456789abcdef")
opts.EncryptionKey = encryptionKey
opts.EncryptionKeyRotationDuration = 10 * 24 * time.Hour

db, err := badger.Open(opts)

When encryption is enabled, all data on disk (LSM tree and value log) is encrypted. The encryption key must be provided on every Open call.

In-Memory Mode

opts := badger.DefaultOptions("").WithInMemory(true)
db, err := badger.Open(opts)

Useful for testing or ephemeral caches. No data is persisted to disk.

Performance Tuning

For write-heavy workloads (blockchain node sync):

opts.NumMemtables = 10
opts.NumLevelZeroTables = 10
opts.NumLevelZeroTablesStall = 20
opts.NumCompactors = 8
opts.Compression = options.ZSTD

For read-heavy workloads (indexer queries):

opts.NumMemtables = 3
opts.BlockCacheSize = 256 << 20 // 256MB block cache
opts.IndexCacheSize = 128 << 20 // 128MB index cache

Platform Support

PlatformLockingNotes
Linux/macOS/BSDPOSIX flockFull support
WindowsLockFileExFull support
AIXNo fsyncReduced durability guarantees
Plan9/WASMNo lockingSingle-process only

On this page