happydb is a learning-oriented relational database implementation in Java
that explores storage engines, indexing, transactions, recovery, query
execution, query optimization, and basic replication ideas in one repository.
It is not a production database. It is a systems project built to understand how the pieces of a small database fit together end to end.
- Project page: happysnaker.github.io/happydb
- Good fit for: database internals study, systems-project portfolios, storage / transaction / optimizer interviews
- heap-file storage and page management
- B+ tree and hash indexes
- row-level locking and MVCC-style visibility
- redo / undo logging and recovery
- simple SQL parsing and execution
- join / aggregate / filter / order-by operators
- cost-based query optimization experiments
- Raft-based replication experiments
- Netty-based client/server transport
- Storage layer with page abstractions, buffer-pool logic, heap pages, and table metadata management
- Index layer with both B+ tree and hash index implementations
- Transaction path with row-level locking, deadlock-related coordination, undo-log chains, and visibility handling
- Recovery path with redo / undo logs, checkpoints, and crash-recovery support
- Execution engine supporting filtering, joins, grouping, sorting, and scan operators
- Optimizer experiments using histograms and simple cost/cardinality estimation
- Replication experiments around Raft-style log replication and leader / follower roles
src/main/java/happydb/common/ bytes, files, catalog, shared utilities
src/main/java/happydb/storage/ records, pages, heap files, buffer pool
src/main/java/happydb/index/ B+ tree and hash index implementations
src/main/java/happydb/log/ redo / undo logging and recovery
src/main/java/happydb/transaction/ locks, transactions, read views
src/main/java/happydb/parser/ SQL parsing
src/main/java/happydb/execution/ query operators and executor
src/main/java/happydb/optimizer/ histogram + join-plan experiments
src/main/java/happydb/replication/ Raft-style replication experiments
src/main/java/happydb/transport/ Netty-based client/server transport
src/test/java/happydb/ unit and subsystem tests
docs/ implementation notes and lab writeups
flowchart LR
SQL["SQL / client request"] --> Parser["parser"]
Parser --> Plan["logical / physical plan"]
Plan --> Exec["execution operators"]
Exec --> Storage["heap pages / buffer pool"]
Exec --> Index["B+ tree / hash indexes"]
Storage --> Log["redo / undo logs"]
Storage --> Tx["locks / MVCC / read view"]
Log --> Recovery["checkpoint / recovery"]
Exec --> Net["Netty transport"]
Storage --> Repl["Raft experiments"]
If you are skimming this repository as a portfolio / systems project, a good reading order is:
storage/— page, record, and buffer-pool foundationsindex/btree/andindex/hash/— index implementationstransaction/andlog/— concurrency control and recovery mechanicsexecution/andoptimizer/— query operators and planningreplication/— replication and fault-tolerance experiments
This is a serious learning project, not a hardened production database.
Known tradeoffs / limitations include:
- index-page logging and recovery semantics are simplified
- some SQL and locking scenarios are intentionally incomplete
FOR UPDATE/ next-key-locking style behavior is not fully implemented- replication and operational hardening are exploratory rather than complete
- some performance claims come from development-time experiments, not a formal benchmark suite
That said, the repository still demonstrates real implementation depth across database internals, concurrency control, logging, and systems design.
- JDK: 19 (per current Maven compiler settings)
- Build tool: Maven
Open the repository in IntelliJ IDEA or another Java IDE with Maven support.
This repository was influenced in part by database systems coursework such as MIT 6.830 / SimpleDB-style exercises, but the implementation structure, extensions, and combined feature set here go beyond a straight course skeleton.
For deeper implementation notes, see:
CSAPPLabsAndNotes— systems-learning notes and CS:APP walkthroughsgo-service-starter— minimal production-minded Go HTTP service startersystem-design-checklist— practical checklist and answer sheet for architecture reviews and distributed-systems tradeoffs
If this repo helped your database-internals learning, systems interview prep, or implementation work:
- give it a star
- share it with other learners working on storage / database fundamentals
- support ongoing maintenance via the support page
- shortest support thread: If happydb helped, here is the shortest support path
- if this project saved you meaningful study time, a small direct tip such as
¥19.9/¥49.9is already helpful - if you want compact async feedback on your GitHub profile, repo README, or
portfolio packaging, I also offer a lightweight
¥99async review on the support page
MIT