Ctrl Plane

Badger Store

Embedded key-value store using BadgerDB for single-node persistence.

The Badger store uses BadgerDB for embedded key-value persistence. It gives you durable storage without an external database process.

When to use

  • Single-node deployments — embedded database with no external dependencies.
  • Edge/IoT — lightweight persistence for resource-constrained environments.
  • Desktop applications — local data storage without a database server.
  • Testing with persistence — faster than PostgreSQL, data survives restarts.

Configuration

import "github.com/xraph/ctrlplane/store/badger"

s, err := badger.New(badger.Config{
    Path:       "./data/badger",
    InMemory:   false,
    SyncWrites: false,
})
FieldEnvDefaultDescription
PathCP_BADGER_PATH./data/badgerDirectory for data files
InMemoryCP_BADGER_IN_MEMORYfalseRun in memory (for testing)
SyncWritesCP_BADGER_SYNC_WRITESfalseFsync on every write (slower, safer)

Or use it with the app:

s, err := badger.New(badger.Config{Path: "./data"})

cp, err := app.New(
    app.WithStore(s),
)

Internals

AspectDetail
StorageLSM tree + value log (BadgerDB v4)
SerializationJSON encoding for all values
Key scheme{prefix}{tenant_id}:{entity_id}
MigrateNo-op (no schema)
PingOpens a read-only transaction to verify access
CloseCloses the BadgerDB instance

Key prefixes

Each entity type has a dedicated prefix for efficient iteration:

inst:  — instances          depl:  — deployments
rels:  — releases           hchk:  — health checks
hrsl:  — health results     metr:  — metrics
logs:  — log entries        trac:  — traces
rsna:  — resource snapshots doma:  — domains
rout:  — routes             cert:  — certificates
secr:  — secrets            tent:  — tenants
audt:  — audit entries

Secondary indexes use additional prefixes (islg: for instance slugs, tslg: for tenant slugs).

Operations

  • Insert — JSON-marshal the entity and set with the key.
  • Get — Direct key lookup, JSON-unmarshal.
  • List — Prefix scan with BadgerDB iterator, filter by tenant and criteria.
  • Update — Overwrite the key with the new value.
  • Delete — Remove the key.

Limitations

  • Single process — BadgerDB holds a directory lock; only one process can open the database at a time.
  • No SQL queries — filtering is done in application code during iteration.
  • No multi-node — not suitable for distributed deployments.
  • JSON overhead — serialization adds some latency compared to binary formats.

Comparison

FeatureMemoryBadgerBunMongoDB
SetupNonePath onlyDSNURI
PersistenceNoYesYesYes
Multi-processNoNoYesYes
Query flexibilityLowLowHighHigh
Best forTestsEmbeddedProduction SQLProduction NoSQL

On this page