Skip to main content

A high-performance graph database with ACID transactions

Project description

Sombra - A Graph Database in Rust

Sombra is a file-based graph database inspired by SQLite's single-file architecture. Built in Rust with a focus on correctness, performance, and ACID transaction support.

Features

Core Features

  • Property Graph Model: Nodes, edges, and flexible properties
  • Single File Storage: SQLite-style database files
  • ACID Transactions: Full transactional support with rollback
  • Write-Ahead Logging: Crash-safe operations
  • Page-Based Storage: Efficient memory-mapped I/O

Performance Features ✨ NEW

  • Label Index: Fast label-based queries with O(1) lookup
  • LRU Node Cache: 90% hit rate for repeated reads
  • B-tree Primary Index: 25-40% memory reduction, better cache locality
  • Optimized Graph Traversals: 18-23x faster than SQLite for graph operations
  • Performance Metrics: Real-time monitoring of cache, queries, and traversals
  • Scalability Testing: Validated for 100K+ node graphs

Language Support

  • Rust API: Core library with full feature support
  • TypeScript/Node.js API: Complete NAPI bindings for JavaScript/TypeScript
  • Python API: PyO3 bindings with native performance (build with maturin -F python)
  • Cross-Platform: Linux, macOS, and Windows support

Testing & Quality

  • 39 Comprehensive Tests: Unit, integration, and stress tests
  • Production Ready: Zero breaking changes, automatic migration
  • Benchmark Suite: Performance regression testing

Quick Start

Rust API

use sombra::prelude::*;

// Open or create a database
let mut db = GraphDB::open("my_graph.db")?;

// Use transactions for safe operations
let mut tx = db.begin_transaction()?;

// Add nodes and edges
let user = tx.add_node(Node::new(0))?;
let post = tx.add_node(Node::new(1))?;
tx.add_edge(Edge::new(user, post, "AUTHORED"))?;

// Commit to make changes permanent
tx.commit()?;

// Query the graph
let neighbors = db.get_neighbors(user)?;
println!("User {} authored {} posts", user, neighbors.len());

TypeScript/Node.js API

import { SombraDB, SombraPropertyValue } from 'sombradb';

const db = new SombraDB('./my_graph.db');

const createProp = (type: 'string' | 'int' | 'float' | 'bool', value: any): SombraPropertyValue => ({
  type,
  value
});

const alice = db.addNode(['Person'], {
  name: createProp('string', 'Alice'),
  age: createProp('int', 30)
});

const bob = db.addNode(['Person'], {
  name: createProp('string', 'Bob'),
  age: createProp('int', 25)
});

const knows = db.addEdge(alice, bob, 'KNOWS', {
  since: createProp('int', 2020)
});

const aliceNode = db.getNode(alice);
console.log('Alice:', aliceNode);

const neighbors = db.getNeighbors(alice);
console.log(`Alice has ${neighbors.length} connections`);

const bfsResults = db.bfsTraversal(alice, 3);
console.log('BFS traversal:', bfsResults);

const tx = db.beginTransaction();
try {
  const charlie = tx.addNode(['Person'], {
    name: createProp('string', 'Charlie')
  });
  tx.addEdge(alice, charlie, 'KNOWS');
  tx.commit();
} catch (error) {
  tx.rollback();
  throw error;
}

db.flush();
db.checkpoint();

Python API

from sombra import SombraDB

db = SombraDB("./my_graph.db")

alice = db.add_node(["Person"], {"name": "Alice", "age": 30})
bob = db.add_node(["Person"], {"name": "Bob", "age": 25})

db.add_edge(alice, bob, "KNOWS", {"since": 2020})

node = db.get_node(alice)
print(f"Alice -> {node.labels}, properties={node.properties}")

neighbors = db.get_neighbors(alice)
print(f"Alice has {len(neighbors)} connections")

tx = db.begin_transaction()
try:
    charlie = tx.add_node(["Person"], {"name": "Charlie"})
    tx.add_edge(alice, charlie, "KNOWS")
    tx.commit()
except Exception:
    tx.rollback()
    raise

Installation

Rust

cargo add sombra

TypeScript/Node.js

npm install sombra

Python

# Install from PyPI (coming soon)
pip install sombra

# Or build from source
pip install maturin
maturin build --release -F python
pip install target/wheels/sombra-*.whl

Architecture

Sombra is built in layers:

  1. Storage Layer: Page-based file storage with 8KB pages
  2. Pager Layer: In-memory caching and dirty page tracking
  3. WAL Layer: Write-ahead logging for crash safety
  4. Transaction Layer: ACID transaction support
  5. Graph API: High-level graph operations
  6. NAPI Bindings: TypeScript/Node.js interface layer

Documentation

User Guides

Technical Specifications

Planning & Development

Testing

# Run all tests
cargo test

# Run transaction tests specifically
cargo test transactions

# Run smoke tests
cargo test smoke

# Run stress tests
cargo test stress

Performance

Phase 1 Optimizations ✅ COMPLETE

Sombra now includes production-ready performance optimizations:

Optimization Improvement Status
Label Index Fast O(1) label queries ✅ Complete
Node Cache 90% hit rate for repeated reads ✅ Complete
B-tree Index 25-40% memory reduction ✅ Complete
Metrics System Real-time monitoring ✅ Complete

Benchmark Results (100K nodes):

Node Lookups:    ~1.5M ops/sec
Neighbor Queries: ~9.9M ops/sec  
Index Memory:    25% reduction (3.2MB → 2.4MB)
Cache Hit Rate:  90% after warmup

Graph Traversal Performance (vs SQLite):

  • Medium Dataset: 7,778 ops/sec vs 452 ops/sec (18x faster)
  • Large Dataset: 1,092 ops/sec vs 48 ops/sec (23x faster)

Running Benchmarks

# Index performance comparison
cargo bench --bench index_benchmark --features benchmarks

# BFS traversal performance
cargo bench --bench small_read_benchmark --features benchmarks

# Scalability testing (50K-500K nodes)
cargo bench --bench scalability_benchmark --features benchmarks

# Performance metrics demo
cargo run --example performance_metrics_demo --features benchmarks

Current Status

Phase 1 Complete (Production Ready):

  • Core graph operations (add/get nodes and edges)
  • Page-based storage with B-tree indexing
  • Write-ahead logging (WAL)
  • ACID transactions with rollback
  • Crash recovery
  • Label secondary index
  • LRU node cache
  • Optimized graph traversals (18-23x faster than SQLite)
  • Performance metrics system
  • TypeScript/Node.js NAPI bindings
  • Comprehensive test suite (39/39 passing)

🚧 Phase 2 Planned (Next 2-3 months):

  • Adjacency indexing (5-10x traversal speedup)
  • Property-based indexes
  • Query planner with cost-based optimization
  • Concurrent readers

🔮 Phase 3 Future:

  • CSR representation for dense graphs
  • Neighbor caching for hub nodes
  • Path compression
  • Custom B-tree implementation

Examples

See the tests/ directory for comprehensive examples:

  • tests/smoke.rs - Basic usage patterns
  • tests/stress.rs - Performance and scalability
  • tests/transactions.rs - Transaction usage examples

License

This project is open source. See LICENSE for details.

Contributing

See Contributing Guidelines for information on how to contribute to Sombra.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sombra-0.1.28-cp314-cp314-win_amd64.whl (309.5 kB view details)

Uploaded CPython 3.14Windows x86-64

sombra-0.1.28-cp314-cp314-manylinux_2_34_x86_64.whl (471.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

sombra-0.1.28-cp314-cp314-macosx_11_0_arm64.whl (416.1 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

sombra-0.1.28-cp313-cp313-win_amd64.whl (311.8 kB view details)

Uploaded CPython 3.13Windows x86-64

sombra-0.1.28-cp313-cp313-manylinux_2_34_x86_64.whl (474.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

sombra-0.1.28-cp313-cp313-macosx_11_0_arm64.whl (418.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

sombra-0.1.28-cp312-cp312-win_amd64.whl (312.3 kB view details)

Uploaded CPython 3.12Windows x86-64

sombra-0.1.28-cp312-cp312-manylinux_2_34_x86_64.whl (475.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

sombra-0.1.28-cp312-cp312-macosx_11_0_arm64.whl (419.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

sombra-0.1.28-cp311-cp311-win_amd64.whl (305.7 kB view details)

Uploaded CPython 3.11Windows x86-64

sombra-0.1.28-cp311-cp311-manylinux_2_34_x86_64.whl (470.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

sombra-0.1.28-cp311-cp311-macosx_11_0_arm64.whl (415.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file sombra-0.1.28-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: sombra-0.1.28-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 309.5 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for sombra-0.1.28-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 36f844621559083a7b6633ae4eb5bd0724d47dd6886ef478f29cd609927d1349
MD5 c073344899ec2a0375f7d2cb93b86d8b
BLAKE2b-256 0a35e676e808d06552057432be464267213d71897a7ffbe898958bc2dcc520f7

See more details on using hashes here.

File details

Details for the file sombra-0.1.28-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for sombra-0.1.28-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bd1745ff7990e5ff803f0b8a196d1abdc6956a5d1709e0ade1033132c42d761f
MD5 6c3abd584c4f7e84409daea8f9941704
BLAKE2b-256 fe3f6063372446a4878254f70b36345695b6e1021a6ddb5f16cccb638a52b45a

See more details on using hashes here.

File details

Details for the file sombra-0.1.28-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sombra-0.1.28-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8825009920c7251a30dba908ad1843fb78e06569d460bdcb4d4625e68ef121ba
MD5 3fbecc30ef7c055309ac6580ffd0da5b
BLAKE2b-256 0567988e0549f4b7283a189044bd4dc0bd8fe379e81655a1fbce4c4c98e80709

See more details on using hashes here.

File details

Details for the file sombra-0.1.28-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: sombra-0.1.28-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 311.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for sombra-0.1.28-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 45a53bd2e47e09cd04e66702f009e078714622fe133dc0d29f56404fb8a99c47
MD5 2812db125fd0d41443e9cc02d946437f
BLAKE2b-256 29bb801dfe7ce6669a81504564defe9e6db7170a18b36f131a656c21e783aa06

See more details on using hashes here.

File details

Details for the file sombra-0.1.28-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for sombra-0.1.28-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a225f72d85bc8acf0731cacde359798da4aaf6bd483e94906990ee35e2d1587e
MD5 c86240aed51fb2322184ab17347aad3b
BLAKE2b-256 47f9d6a5822e4cd816719f83477d120ea45d880b7156b2b6c651ac4aee54d50e

See more details on using hashes here.

File details

Details for the file sombra-0.1.28-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sombra-0.1.28-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5eecc470ff1bcb4d61a2d66eade6d3703242d7b1a05bbaaa67af5a805e52ff0c
MD5 4df45d20368fc4fcece10cf2ec6b9f89
BLAKE2b-256 1ff59a8d98c73204ab2d092037e9aa73c1fb018742e59f62dcb084e2d799fb21

See more details on using hashes here.

File details

Details for the file sombra-0.1.28-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: sombra-0.1.28-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 312.3 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for sombra-0.1.28-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 62f36633732b8ed731d9b2f6968a62ce2242216b4a9cef7bd828c961a772b87f
MD5 44858f1f60c2f313222a54f25d9a88dc
BLAKE2b-256 5f17d2f352aafe449da0962642773253f1910106e76815c1492fa45aa819ec2e

See more details on using hashes here.

File details

Details for the file sombra-0.1.28-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for sombra-0.1.28-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a1204f2c895bb3d41e5a403cef344d73cbea10dc304d22f1d5327ac25a437fb4
MD5 4d2547b88928fcb4a834407d81eafa40
BLAKE2b-256 60416a1f6f947829857fdb14bd8096b1c1d7ebec0a97098dfa5c26a076417599

See more details on using hashes here.

File details

Details for the file sombra-0.1.28-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sombra-0.1.28-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5daa7223f664f073cbedc6fa1241f626c08bc039f9153b064fbc8f1e87e38fc9
MD5 59d3cad5faf4f8cafdd1c3dc3e9a4df1
BLAKE2b-256 e5629705a3b54b8e7ba23a6ea77302f73e10535ac1172dc3caaf6d4301029f17

See more details on using hashes here.

File details

Details for the file sombra-0.1.28-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: sombra-0.1.28-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 305.7 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for sombra-0.1.28-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0f5b295160fff1c41805d827dcdab66aedb418404d985f90a59859d18b4a1f73
MD5 ebeade5eeb61311548291c16ee16b776
BLAKE2b-256 1c03eaf985b25b4d402b592b162b5854c641c465da7bb1198bb95a7936fc1550

See more details on using hashes here.

File details

Details for the file sombra-0.1.28-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for sombra-0.1.28-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 484107471f6814ce32724c3c9e46ca248ab5495b9dc38088269f3fa142975c26
MD5 64abbb755162cdcadfa1d18c2b5eff30
BLAKE2b-256 8cb83aed36af434fbf7018690507d70feadba84144958fcd3115d343cf7a3507

See more details on using hashes here.

File details

Details for the file sombra-0.1.28-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sombra-0.1.28-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f2cb44eee3c8c7440e44782ae1f9d50de02f64abe24f8d1a1a6e100a129ccc9d
MD5 70b8456ee0f0f816f134e08b6b069d82
BLAKE2b-256 837980955f63a2a065c3d89cf2bc9ac90bfeb8a833726008b303494763a3b16a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page