Hey there! 👋 This is my journey of building a database from scratch using Go. I really wanted to understand how databases actually work under the hood, but quickly turned into a fascinating deep-dive into database internals.
After many late nights and countless cups of coffee, I've implemented full ACID compliance:
- Atomicity: All or nothing - transactions either fully complete or fully roll back
- Consistency: The database remains valid after every transaction
- Isolation: Concurrent transactions don't step on each other's toes
- Durability: Once committed, data stays committed (yes, even if your machine crashes!)
This was probably the trickiest part! The engine supports:
- Multiple transactions running simultaneously
- Deadlock detection
- Lock management to prevent dirty reads/writes
- Transaction isolation levels
I chose B+ Trees because they're practically the industry standard for database indexes. My implementation includes:
- Efficient range queries
- Auto-balancing on insert/delete
- Disk-friendly node structure
- Configurable node size
While it's not full SQL (yet!), the query language supports basic operations:
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(50),
age INT
)
INSERT INTO users (name, age) VALUES ("Alice", 30)
UPDATE users SET age = 31 WHERE id = 1
SELECT name, age FROM users
This is very much a learning project and a work in progress. While it works, there's still a lot I want to add:
- Basic CRUD operations
- ACID transactions
- B+ Tree indexes
- Table creation and schema management
- Simple query parser
- Implement Raft Algorithm
- Make it a proper distributed database
I believe the best way to truly understand how something works is to build it from scratch. While I wouldn't recommend using this in production, building this has taught me more about databases than using them.
If you're interested in building your own database, here are some resources I found incredibly helpful:
- Database Internals book
- Build Your Own book
Feel free to open issues or PRs if you spot bugs or have suggestions! While this is primarily a learning project, I'm always happy to collaborate and learn from others.
MIT
Built with Go and lots of debugging sessions 🔍