Internals
Architecture
How KiteDB is structured internally
KiteDB is built in three layers. The query layer is the API you call, the graph layer manages nodes, edges, and transactions, and the storage layer keeps everything in a single file on disk.
The three layers
Query layer
Fluent API, type inference, schema validation
db.insert(user).values({...})Graph layer
Nodes, edges, traversal, transactions
create_node()add_edge()out_edges()Storage layer
Memory-mapped file, crash recovery
Query layer
This is what you interact with. It provides the Drizzle-style API with full TypeScript type inference. When you write db.insert(user).values(...), the query layer validates your schema, converts TypeScript types to storage types, and calls into the graph layer.
Graph layer
Manages the graph abstraction: nodes with properties, edges between nodes, and traversals. Handles transaction boundaries and coordinates reads between the snapshot and delta.
Storage layer
Stores data in a format built for graph operations. It is organized around the snapshot + delta model, which separates an immutable snapshot on disk from the changes made since it was written.
What happens when you insert a node
Here is the path a single insert takes:
const alice = db .insert(user) .values({ key: 'alice', name: 'Alice', age: 30 }) .returning();Query layer
user has its required propertiesage: 30 to the internal I64 typecreate_node(...)Graph layer
NodeId from a monotonic counterStorage layer
CREATE_NODE record for durabilitycreated_nodes mapWhat happens when you read
Reads merge data from two sources:
const alice = db.get(user, 'alice');Key index lookup
delta.key_index for recent changesNodeIdProperty fetch
delta.modified_nodes for changesReturns the latest committed data
Why this design
| Design choice | Benefit |
|---|---|
| Snapshot + delta | Reads don't block writes. The snapshot is immutable and the delta is small. |
| CSR format for edges | Traversals read contiguous memory, which makes good use of CPU caches. |
| WAL for durability | Committed data survives crashes. Recovery only replays the WAL written since the last checkpoint. |
| Single file | Portable, atomic operations, simpler deployment. |
| Memory-mapped I/O | The OS page cache keeps hot pages in memory. Uncompressed sections are read in place. |
Next steps
- Snapshot and delta – the core storage model in detail
- CSR format – how edges are stored
- Single-file format – the
.kitedbfile layout