# erikgrinaker/toydb

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/erikgrinaker-toydb).**

7,251 stars · 626 forks · Rust · Apache-2.0

## Links

- GitHub: https://github.com/erikgrinaker/toydb
- awesome-repositories: https://awesome-repositories.com/repository/erikgrinaker-toydb.md

## Description

ToyDB is a distributed SQL database that provides a system for storing and querying data across multiple nodes. It focuses on maintaining strong consistency and fault tolerance through the implementation of a distributed consensus algorithm.

The project distinguishes itself by supporting historical data versioning, enabling time-travel queries to retrieve the state of the database from a specific point in the past. It utilizes multi-version concurrency control to manage ACID transactions and ensure data integrity during concurrent operations.

The system covers relational data modeling with table schemas, primary keys, and foreign keys to enforce referential integrity. Its query engine parses SQL statements and executes them through an optimized pipeline of operators, supporting joins, aggregations, and heuristic query optimization. Data is persisted via pluggable storage backends, including log-structured and in-memory engines.

## Tags

### Data & Databases

- [Distributed SQL Databases](https://awesome-repositories.com/f/data-databases/distributed-sql-databases.md) — Implements a relational database engine designed to scale horizontally while maintaining transactional consistency.
- [ACID Transactional Cores](https://awesome-repositories.com/f/data-databases/acid-transactional-cores.md) — Ensures data integrity using snapshot isolation and multi-version concurrency control to prevent dirty and phantom reads. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/sql.md))
- [Historical Data Querying Interfaces](https://awesome-repositories.com/f/data-databases/data-access-querying/historical-data-querying-interfaces.md) — Allows retrieval of the database state from specific points in the past using logical timestamps. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/examples.md))
- [Time-Travel Query Interfaces](https://awesome-repositories.com/f/data-databases/data-access-querying/historical-data-querying-interfaces/time-travel-query-interfaces.md) — Enables retrieval of past table states using snapshot identifiers or transaction timestamps. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/sql.md))
- [Data Joins](https://awesome-repositories.com/f/data-databases/data-joins.md) — Implements general purpose joining functionality to merge columns from multiple tables based on shared keys. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/examples.md))
- [Data Querying](https://awesome-repositories.com/f/data-databases/data-querying.md) — Provides interfaces for filtering, sorting, and retrieving stored data collections. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/sql.md))
- [Data Replication](https://awesome-repositories.com/f/data-databases/data-replication.md) — Synchronizes an ordered command log across distributed nodes to ensure data consistency and availability. ([source](https://github.com/erikgrinaker/toydb/blob/main/src/raft/mod.rs))
- [Table Schemas](https://awesome-repositories.com/f/data-databases/database-management-systems/database-systems-management/database-management/schema-designers/table-schemas.md) — Supports the creation of tables with specific data types, primary keys, unique constraints, and foreign key relationships. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/sql.md))
- [SQL Query Execution](https://awesome-repositories.com/f/data-databases/database-management-systems/database-systems-management/database-operations/sql-query-execution.md) — Executes structured SQL statements and transactions using an optimized engine to retrieve or modify data. ([source](https://github.com/erikgrinaker/toydb#readme))
- [Schema Definitions](https://awesome-repositories.com/f/data-databases/database-schema-designers/schema-definitions.md) — Provides capabilities to create and remove tables with basic datatypes, primary keys, foreign keys, and column indexes. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/examples.md))
- [Distributed Consensus Protocols](https://awesome-repositories.com/f/data-databases/distributed-consensus-protocols.md) — Replicates state across a cluster using a consensus protocol to maintain consistency across all nodes. ([source](https://github.com/erikgrinaker/toydb#readme))
- [Consensus Algorithms](https://awesome-repositories.com/f/data-databases/distributed-state-synchronizers/consensus-algorithms.md) — Implements consensus algorithms to ensure all nodes in the cluster agree on the sequence of operations. ([source](https://github.com/erikgrinaker/toydb/blob/main/.gitignore))
- [Fault Tolerant Storage](https://awesome-repositories.com/f/data-databases/fault-tolerant-storage.md) — Maintains data availability and operational status as long as a majority of cluster nodes remain functional. ([source](https://github.com/erikgrinaker/toydb/blob/main/src/raft/mod.rs))
- [Multi-Version Concurrency Control](https://awesome-repositories.com/f/data-databases/multi-version-concurrency-control.md) — Tracks data versions via logical timestamps to provide snapshot isolation and enable time-travel queries.
- [Multi-Version Concurrency Controls](https://awesome-repositories.com/f/data-databases/multi-version-concurrency-controls.md) — Uses multi-version concurrency control to enable lock-free reads and writes via data versioning. ([source](https://github.com/erikgrinaker/toydb#readme))
- [Multi-Version Concurrency Control](https://awesome-repositories.com/f/data-databases/multi-version-concurrency-controls/multi-version-concurrency-control.md) — Utilizes multi-version concurrency control to provide snapshot isolation and ensure data integrity during concurrent operations.
- [Query Execution Pipelines](https://awesome-repositories.com/f/data-databases/query-execution-pipelines.md) — Processes SQL statements by pulling and transforming data rows through a pipeline of operator nodes.
- [Referential Integrity Constraints](https://awesome-repositories.com/f/data-databases/referential-integrity-constraints.md) — Blocks deletions, updates, or insertions that violate primary key constraints or foreign key references. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/examples.md))
- [Relational Data Modeling](https://awesome-repositories.com/f/data-databases/relational-data-modeling.md) — Provides capabilities for organizing data into structured tables with primary keys and foreign key relationships.
- [Row Deletions](https://awesome-repositories.com/f/data-databases/row-deletions.md) — Removes rows from a table that match a specific boolean condition. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/sql.md))
- [Row Insertions](https://awesome-repositories.com/f/data-databases/row-insertions.md) — Provides the ability to add new records to tables using standard SQL insert operations. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/sql.md))
- [SQL-Based Row Updates](https://awesome-repositories.com/f/data-databases/sql-based-row-updates.md) — Allows modification of existing records in a table using SQL expressions and conditional predicates. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/sql.md))
- [SQL Query Execution Engines](https://awesome-repositories.com/f/data-databases/sql-query-execution-engines.md) — Provides an engine that processes standard SQL commands while maintaining strict consistency and isolation. ([source](https://github.com/erikgrinaker/toydb/blob/main/src/sql/execution/executor.rs))
- [Strong Consistency Guarantees](https://awesome-repositories.com/f/data-databases/strong-consistency-guarantees.md) — Guarantees linearizability by routing writes through a leader and confirming them via a quorum. ([source](https://github.com/erikgrinaker/toydb/blob/main/src/raft/mod.rs))
- [Table Deletion](https://awesome-repositories.com/f/data-databases/table-definitions/table-deletion.md) — Permanently deletes a table and all its associated data from the system. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/sql.md))
- [Log-Structured Storage Engines](https://awesome-repositories.com/f/data-databases/write-ahead-logging/log-structured-storage-engines.md) — Persists data to an append-only file and maintains an in-memory index of keys to file offsets.
- [Write Conflict Resolution Policies](https://awesome-repositories.com/f/data-databases/duplicate-detection-tools/write-conflict-resolution-policies.md) — Detects concurrent transactions modifying the same key and resolves conflicts using specific policies. ([source](https://github.com/erikgrinaker/toydb/blob/main/src/storage/mvcc.rs))
- [Mathematical Evaluators](https://awesome-repositories.com/f/data-databases/expression-engines/mathematical-evaluators.md) — Computes results using standard arithmetic operators, floating point math, and three-valued logic. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/examples.md))
- [Grouped Aggregations](https://awesome-repositories.com/f/data-databases/grouped-aggregations.md) — Reduces grouped data into scalar summaries such as average, count, and sum. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/sql.md))
- [Append-Only Log Stores](https://awesome-repositories.com/f/data-databases/key-value-stores/append-only-log-stores.md) — Writes data to an append-only log while maintaining an in-memory map of keys to file offsets. ([source](https://github.com/erikgrinaker/toydb/blob/main/src/storage/bitcask.rs))
- [Pluggable Storage Drivers](https://awesome-repositories.com/f/data-databases/pluggable-storage-drivers.md) — Decouples database logic from the persistence layer using a pluggable interface for interchangeable storage engines.
- [Pluggable Storage Engines](https://awesome-repositories.com/f/data-databases/pluggable-storage-engines.md) — Supports interchangeable storage backends, including log-structured and in-memory engines. ([source](https://github.com/erikgrinaker/toydb/blob/main/README.md))
- [Query Planning](https://awesome-repositories.com/f/data-databases/query-planning.md) — Rewrites logical execution plans using heuristic strategies to reduce data transmission and computation.
- [SQL Abstract Syntax Tree Parsing](https://awesome-repositories.com/f/data-databases/sql-abstract-syntax-tree-parsing.md) — Processes SQL queries into abstract syntax trees to enable programmatic analysis and execution. ([source](https://github.com/erikgrinaker/toydb/blob/main/src/sql/parser/parser.rs))
- [SQL Aggregate Functions](https://awesome-repositories.com/f/data-databases/sql-aggregate-functions.md) — Provides standard SQL aggregate functions for calculating sums, counts, and averages over datasets. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/examples.md))
- [Storage Backend Adapters](https://awesome-repositories.com/f/data-databases/storage-backend-adapters.md) — Supports swapping between different data persistence layers such as log-structured stores or in-memory engines. ([source](https://github.com/erikgrinaker/toydb#readme))

### Networking & Communication

- [Raft Consensus Implementations](https://awesome-repositories.com/f/networking-communication/distributed-systems-p2p/distributed-systems-coordination/distributed-consensus-protocols/raft-consensus-implementations.md) — Synchronizes a command log across a cluster of nodes using the Raft consensus algorithm for fault tolerance.

### Software Engineering & Architecture

- [Replicated State Machines](https://awesome-repositories.com/f/software-engineering-architecture/state-machine-logic/replicated-state-machines.md) — Maintains identical state across all nodes by applying an ordered sequence of transactions. ([source](https://github.com/erikgrinaker/toydb/blob/main/README.md))
- [Storage Abstractions](https://awesome-repositories.com/f/software-engineering-architecture/storage-abstractions.md) — Uses trait-based interfaces to decouple the core database logic from the underlying persistence layer.

### Programming Languages & Runtimes

- [SQL Expression Evaluation](https://awesome-repositories.com/f/programming-languages-runtimes/expression-evaluators/sql-expression-evaluation.md) — Computes results using logical, comparison, mathematical, and string operators including pattern matching with wildcards. ([source](https://github.com/erikgrinaker/toydb/blob/main/docs/sql.md))

### Part of an Awesome List

- [Database Systems](https://awesome-repositories.com/f/awesome-lists/data/database-systems.md) — Distributed SQL database implementation for educational purposes.
