Skip to main content
Technology & EngineeringDatabase Services34 lines

Verify Embedded Go Key-Value Storage with BadgerDB and Pebble

Exercise BadgerDB transactions or Pebble batches in a disposable Go fixture, distinguish missing keys from failed reads, and verify the application can reopen its committed records.

Quick Summary3 lines
Use this procedure when embedding a local ordered key-value store in a Go application. Choose the branch for the dependency the application uses. Keep the test data small enough to inspect every expected key after reopening the store.
skilldb get database-services-skills/verify-embedded-go-key-value-storesFull skill: 34 lines
Paste into your CLAUDE.md or agent config

Verify Embedded Go Key-Value Storage with BadgerDB and Pebble

Use this procedure when embedding a local ordered key-value store in a Go application. Choose the branch for the dependency the application uses. Keep the test data small enough to inspect every expected key after reopening the store.

Set up the fixture

Pin the module version in the test module and record the Go version. The interfaces below use Badger's v4 module and Pebble's v1 module. Give each engine its own temporary directory. A shared application key schema does not establish file-format compatibility.

Define two related records, such as a primary entry named item/blue and an index named index/color/blue. Decide whether the index is allowed to exist without the primary entry. For this fixture require both records to commit together. Reserve a third key, item/aborted, for checking the cancellation path.

Exercise BadgerDB

Open the fixture directory with badger.Open and options appropriate for the pinned release. Choose WithSyncWrites(true) when the test contract requires the engine to synchronize acknowledged writes to storage. Check the open error before installing cleanup. Keep a single owner for the directory during the test.

Use one db.Update callback for the two related txn.Set calls. Return the first write error immediately and check the error returned by the outer update. In a separate update, stage the aborted record and return a deliberate application error. Confirm that the caller receives that error.

Read the committed records in db.View. Handle badger.ErrKeyNotFound as the expected result only for the deliberately absent key. When passing bytes out of the transaction use item.ValueCopy(nil) and check its error. A value backed by the transaction may no longer be valid after the callback returns.

Exercise Pebble

Open the other directory with pebble.Open. Stage the primary entry and index in one db.NewBatch(), check each Set error, then call batch.Commit(pebble.Sync) and check the result. Close the batch, also on an earlier error. A normal batch accumulates writes. If the application must read its own staged updates, examine the indexed-batch API for the pinned version.

Create a separate batch, stage the aborted key and close that batch without committing it. Use db.Get to verify the two committed values and require pebble.ErrNotFound for the aborted one. A successful get returns borrowed bytes and a closer. Copy the bytes if they must survive the read, then close the handle and handle its error. A failed get has no successful read handle to close.

Reopen and check the application contract

Release outstanding reads, transactions and batches, close the database and check the close error. Reopen the same directory with the same engine. Confirm both committed values, their exact bytes, and the absence of the aborted record. An empty value at a present key must remain distinguishable from a missing key.

Record the engine and version, write options, actual keys and expected observations from the synthetic fixture. Report any mismatch as an application or integration failure. A successful orderly reopen exercises persistence across a clean restart. Power-loss guarantees, backups, cross-engine migrations and throughput require separate evidence.

Install this skill directly: skilldb add database-services-skills

Get CLI access →

Related Skills

Cassandra

Build with Apache Cassandra for high-availability distributed data. Use this skill when the project needs a wide-column database for massive write throughput, multi-region replication, or always-on availability. Covers data modeling, partition keys, CQL, the cassandra-driver for Node.js, and operational patterns for production clusters.

Database Services•225L

Clickhouse

Build with ClickHouse for real-time analytics and OLAP workloads. Use this skill when the project needs columnar storage for fast aggregation queries over billions of rows — log analytics, event tracking, product analytics, or business intelligence. Covers table engines, MergeTree family, materialized views, and the ClickHouse Node.js client.

Database Services•259L

Cockroachdb

Build with CockroachDB as a distributed SQL database. Use this skill when the project needs to integrate CockroachDB for globally distributed PostgreSQL-compatible SQL, multi-region deployments, serializable transactions, or horizontal scaling. Covers CockroachDB Serverless, node-postgres integration, multi-region patterns, and ORM compatibility.

Database Services•194L

Convex

Build with Convex as a reactive backend. Use this skill when the project needs to integrate Convex for real-time database, server functions, file storage, scheduled jobs, authentication, or full-stack TypeScript development with automatic reactivity. Covers the Convex client, queries, mutations, actions, schema validation, indexes, real-time subscriptions, and deployment.

Database Services•306L

Drizzle

Use Drizzle ORM for type-safe SQL in TypeScript. Use this skill when the project needs to integrate Drizzle for SQL-first database access, schema definition in TypeScript, migrations, relational queries, or connecting to PostgreSQL, MySQL, SQLite, Turso, Neon, PlanetScale, or Vercel Postgres. Covers Drizzle schema, query builder, relational API, migrations, and driver integrations.

Database Services•292L

Dynamodb

Build with Amazon DynamoDB as a serverless NoSQL database. Use this skill when the project needs to integrate DynamoDB for key-value and document storage, single-table design, global tables, streams, TTL, or serverless-first data access. Covers the AWS SDK v3, single-table design, GSIs, queries, scans, transactions, and DynamoDB Streams.

Database Services•243L