Skip to content

Architecture

TensorDB is a single-node, append-only, bitemporal ledger database. Every component is designed around one principle: data is immutable.

TensorDB Architecture
πŸ“±
Client
SQL / Rust API / Python / Node.js
β–Ό
⚑
Database Engine
SQL Parser β†’ Planner β†’ Executor
β–Ό hash(key) % shard_count
Shard 0
Single-writer actor
Shard 1
Single-writer actor
Shard 2
Single-writer actor
Shard 3
Single-writer actor
β–Ό
Write Path
WAL
CRC-framed, fsync
β†’
Memtable
Skip list, 4MB
β†’
Flush
SSTable L0
β–Ό
LSM Storage
L0
L1
L2
L3
← Compaction merges levels β†’
Read Path
Cache
Block + Index LRU
β†’
Bloom Filter
10 bits/key
β†’
Temporal Filter
AS OF / VALID AT
AI Runtime (Tier-0)
Risk Scoring
Inline, per-write
Insights
Batched synthesis
Advisors
Query, Cache, Compaction

Core Layers

Database Engine

The Database struct is the public API entry point. It handles:

  • SQL parsing and execution β€” Parses SQL statements, generates query plans, and executes them
  • Shard routing β€” Routes writes to the correct shard via hash(key) % shard_count
  • Configuration β€” Manages all tuning knobs through the Config struct

Shards

Each shard is a single-writer actor that owns:

  • A WAL (write-ahead log) handle
  • An in-memory memtable (skip list)
  • A local commit counter (monotonically increasing)

Shards are independent β€” no coordination between shards is needed for writes. This enables high write throughput through parallelism.

Storage Engine (LSM-Tree)

Data flows through the LSM tree:

  1. WAL β€” Every write is first appended to the write-ahead log with CRC framing
  2. Memtable β€” The write is then inserted into the in-memory skip list
  3. Flush β€” When the memtable reaches memtable_max_bytes (default 4MB), it’s flushed to an L0 SSTable
  4. Compaction β€” L0 SSTables are merged into L1, L1 into L2, etc., up to L6

Design Principles

PrincipleImplementation
ImmutabilityNo in-place updates; all data is append-only
Temporal completenessEvery fact has system time + business time
Crash safetyWAL fsync before acknowledging writes
Lock-free readsShardReadHandle bypasses the actor channel
Zero-copy where possiblemmap reads for SSTable access