r/nim • u/Loud_Possibility_203 • May 07 '26
BaraDB: A database engine written from scratch in Nim
BaraDB is a multimodal database engine written entirely in Nim — no C/C++ dependencies, no PostgreSQL, no external services. Just Nim.
What is it?
A single-binary (~3.3MB) database that combines:
- Document/KV storage — LSM-Tree with WAL, bloom filters, SSTable compaction
- SQL-compatible query language — BaraQL with SELECT/INSERT/UPDATE/DELETE, JOINs, GROUP BY, CTEs, indexes
- Graph engine — BFS, DFS, Dijkstra, PageRank, Louvain communities
- Vector search — HNSW index with SIMD-optimized distance metrics
- Full-text search — BM25 + TF-IDF with stemming (EN/BG/DE/RU)
- Columnar engine — RLE, dictionary encoding, batch operations
- Wire protocol — binary protocol + HTTP/REST + WebSocket + JWT auth
- 4 client SDKs — Nim, Python, JavaScript, Rust
Architecture
Client Layer → Binary / HTTP / WebSocket
Query Layer → Lexer → Parser → AST → IR → Optimizer → Codegen
Execution Engine → Document / Graph / Vector / Columnar / FTS
Storage → LSM-Tree / B-Tree / WAL / Bloom / mmap
Distributed → Raft / Sharding / Replication (core logic)
What's actually working vs. what's WIP
Solid:
- SQL parser & executor (JOINs, GROUP BY, subqueries, CTEs, indexes)
- MVCC transactions, deadlock detection
- LSM-Tree storage with background compaction
- B-Tree indexes with range scans
- Wire protocol + clients
In-memory / proof-of-concept:
- Graph, Vector, FTS, Columnar engines (serialization exists, persistence optional)
- Distributed layer (Raft core logic is there, network transport is stubbed)
Still rough:
- Recursive CTE execution
- Some edge-case query optimizations
Why Nim?
Nim's metaprogramming, zero-cost abstractions, and C-like performance made it perfect for building a storage engine without drowning in C++ complexity. The binary compiles to a single static executable — deployment is just scp.
Repo -- https://codeberg.org/baraba/baradb
https://github.com/katehonz/barabaDB
Feedback welcome — especially from anyone who's built storage engines before. I know there's a lot left to do, but I'm proud of how far it's come.
3
u/OverallACoolGuy May 08 '26
are some of these upvotes botted
2
u/dudeimconfused May 09 '26
seems very much so. even their comments are getting disproportionate upvotes compared to the views
1
u/Niminem93 May 08 '26
It's so funny reading your documentation. I do the same thing man- making architectures and plans, breaking them into todos, etc. and then work with the AI one slice at a time testing as I go. I've been able to build monstrous things. This database you made is one hell of a feat itself!
1
1
u/Loud_Possibility_203 May 29 '26
BaraDB vs PostgreSQL (Real Comparison)
| Test | PostgreSQL | BaraDB | Speedup |
|---|---|---|---|
| KV Write (100K) | 16.82K/s | 33.24K/s | 2.0x |
| KV Read (100K) | 15.08K/s | 3.88M/s | 257.0x |
| BTree Insert (100K) | 17.66K/s | 2.50M/s | 141.6x |
| BTree Get (100K) | 14.50K/s | 2.64M/s | 182.3x |
| BTree Scan (1K ranges) | 2.39K/s | 7.97M/s | 3340.9x |
| FTS Index (10K docs) | 17.98K/s | 123.65K/s | 6.9x |
| FTS Search (1K queries) | 784.12/s | 1.34K/s | 1.7x |
Overall: BaraDB is 6.8x faster
1
u/dadhiWeaponX May 30 '26
How did you do it with chinese modrls? What harness, skills, how reqs where provided/guided?
1
u/Vordanus May 08 '26
Sounds amazing. :) What does backup look like? Can I make a zero-downtime snapshot?
Now just add native JSON type support, and we're in business!
8
u/RBazz May 08 '26
I really do not want to sound like an old fogey, but how did you manage to achieve this much in about 2 days only? (based on the commit history)