Overview

KDB is a lightweight file-based database designed for applications that need fast, reliable data storage without the complexity of traditional database systems. With a compact codebase and zero external dependencies, KDB is ideal for embedded applications and local data storage.

KDB uses a simple delimiter-separated variable-length record format with automatic indexing for fast key-based lookups. The engine includes built-in auto-repair capabilities and file-level locking for safe concurrent access.

Why KDB?

Unlike traditional embedded databases that rely on native libraries, KDB is implemented entirely in managed C#. This provides significant advantages for .NET developers:

  • Pure .NET — No native DLLs, no P/Invoke overhead, no platform-specific binaries to manage
  • Single File Deployment — Just copy one class file. No sqlite3.dll, no version conflicts
  • Human-Readable Data — UTF-8 text format allows direct inspection with any text editor
  • Built-in Auto-Repair — Automatic integrity checking and recovery without external tools
  • Full Code Transparency — Audit, customize, or extend the entire codebase as needed
  • Cross-Platform — Runs anywhere .NET runs, without native library compatibility issues

KDB is ideal when you need simple key-value storage and want to avoid the complexity of managing native database dependencies.

Key Features

Zero Configuration

No server setup, no connection strings, no administration. Just create and use. Single file deployment.

Auto-Repair

Built-in integrity checking and automatic repair on corruption. Data safety without manual intervention.

Fast Lookups

Binary search on indexed keys provides O(log n) read performance. Sorted index for sequential access.

Embeddable

Single class file with no external dependencies. Embed directly into your application.

Concurrent Access

File-level locking allows multiple readers with exclusive write access. Safe for multi-process environments.

UTF-8 Native

Full UTF-8 support for international text. Store any language without encoding issues.

Simple API

KDB provides a straightforward CRUD interface. Create a database, write records, read by key or index, and delete when needed.

// Create database: 3 columns, 1 primary key (max 10 bytes)
int[] pkSizes = new int[] { 10 };
Kdb.Create("mydb", 3, 1, pkSizes);

// Open and write
var db = new Kdb("mydb");
string[] rec = new string[] { "key1", "value1", "value2" };
db.Write(rec);

// Read by key
string[] result = new string[3];
result[0] = "key1";
if (db.Read(result)) {
    // result now contains full record
}

// Iterate all records
int count = db.GetRecordCount();
for (int i = 0; i < count; i++) {
    string[] row = db.ReadIndex(i);
}

Technical Specifications

  • Language — C# (.NET)
  • Codebase — Single class file
  • Data File — .kdb (header + records + EOF)
  • Index File — .kx1 (sorted primary keys + pointers)
  • Encoding — UTF-8
  • Max Primary Keys — 16 columns
  • Search Complexity — O(log n)
  • Dependencies — None

Use Cases

KDB is designed for specific scenarios where simplicity and reliability matter more than scale:

  • Embedded Applications — Desktop apps, utilities, and tools that need local data storage
  • Configuration Storage — Structured settings and preferences with key-based access
  • Small Datasets — Applications with up to 10,000 records
  • Prototyping — Quick data persistence without database server setup
  • Educational — Learning database internals with readable source code

Get Started with KDB

Visit the KDB site for documentation, downloads, and examples.

Visit KDB Site