# NutsDB — Fast Embeddable Key-Value Store in Pure Go > A simple, fast, embeddable, and persistent key/value store written in pure Go with support for lists, sets, sorted sets, and fully serializable transactions. ## Install Save in your project root: # NutsDB — Fast Embeddable Key-Value Store in Pure Go ## Quick Use ```go import "github.com/nutsdb/nutsdb" db, _ := nutsdb.Open(nutsdb.DefaultOptions, nutsdb.WithDir("/tmp/nutsdb")) defer db.Close() db.Update(func(tx *nutsdb.Tx) error { return tx.Put("bucket1", []byte("key"), []byte("value"), 0) }) ``` ## Introduction NutsDB is an embeddable, persistent key/value store written in pure Go. It supports multiple data structures including strings, lists, sets, and sorted sets, all within a single-file database with ACID transaction guarantees. It is designed for applications that need a fast embedded database without running a separate server process. ## What NutsDB Does - Stores key/value pairs with optional TTL expiration - Supports list, set, and sorted set data structures within buckets - Provides fully serializable ACID transactions - Persists data using an append-only log with automatic compaction - Offers prefix and range scan operations for ordered iteration ## Architecture Overview NutsDB uses a bitcask-inspired append-only write model combined with an in-memory index (B+ tree or hash map) for fast lookups. All writes go to a write-ahead entry log on disk, while the in-memory index maps keys to their on-disk positions. Background merge processes compact old log segments to reclaim space. Transactions use a copy-on-write approach with commit-time conflict detection. ## Self-Hosting & Configuration - Import as a Go module: go get github.com/nutsdb/nutsdb - Open a database by specifying a data directory path - Configure segment size, sync strategy, and index type via options - Choose between B+ tree index (range scans) or hash map index (point lookups) - Set entry-level TTL for automatic expiration of stale data ## Key Features - Pure Go implementation with zero CGo dependencies - Multiple data structures (KV, list, set, sorted set) in a unified API - B+ tree index mode enabling efficient prefix and range scans - Configurable TTL per entry for cache-like expiration behavior - Automatic log segment merging for space reclamation ## Comparison with Similar Tools - **BoltDB/bbolt** — B+ tree with page-level MVCC; NutsDB uses a bitcask log with richer data structures (lists, sets) - **BadgerDB** — LSM-tree optimized for SSDs; NutsDB uses an append-only log with simpler compaction - **LevelDB/RocksDB** — C/C++ engines; NutsDB is pure Go with no CGo overhead - **Redis** — in-memory server with similar data structures; NutsDB is an embedded library with disk persistence ## FAQ **Q: Does NutsDB support concurrent access?** A: Yes, NutsDB supports concurrent reads and serialized writes within a single process using its transaction system. **Q: How does TTL work?** A: Each entry can be stored with a TTL in seconds. Expired entries are cleaned up during reads and background merge operations. **Q: What index modes are available?** A: NutsDB offers B+ tree index mode for range scans and prefix queries, and hash map index mode for faster point lookups. **Q: Is NutsDB suitable for production use?** A: NutsDB is used in production by several projects. It works well for embedded storage scenarios where a separate database server is not desired. ## Sources - https://github.com/nutsdb/nutsdb - https://nutsdb.github.io/nutsdb/ --- Source: https://tokrepo.com/en/workflows/asset-5180acdf Author: AI Open Source