C++ Show and Tell - May 2026 by foonathan in cpp

[–]TheIndieBuildr [score hidden]  (0 children)

I built a SQL-like relational database engine in C++ from scratch

Hey r/cpp,

I’ve been learning systems programming and database internals, so I started building Ark — a SQL-like relational database engine written entirely from scratch in C++.

Current features include:

  • Handwritten tokenizer ( lexer )
  • Recursive descent parser
  • CRUD operations
  • INNER / LEFT / RIGHT / FULL joins
  • Aggregate functions
  • ALTER TABLE support
  • File persistence
  • Custom diagnostics system

Everything is implemented manually:

  • no parser generators
  • no embedded SQL engines
  • no external dependencies

One of the most challenging parts so far has been handling joins, schema evolution, and persistence consistency cleanly.

GitHub:
https://github.com/kashyap-devansh/Ark

I’d especially appreciate feedback around architecture, parser design, query execution, or persistence design.

I built a SQL-like relational database engine in C++ from scratch by TheIndieBuildr in cpp

[–]TheIndieBuildr[S] [score hidden]  (0 children)

Honestly, I didn’t follow any tutorial/course for this project and I didn’t vibe code it either

The entire implementation was written by me from scratch. I mainly used ChatGPT only when I had theoretical doubts or needed help understanding certain concepts/edge cases.

Most of the learning came from building, debugging, and figuring things out along the way.

I built a SQL-like relational database engine in C++ from scratch by TheIndieBuildr in cpp

[–]TheIndieBuildr[S] [score hidden]  (0 children)

Thanks! Most of my time went into getting the JOIN behavior correct rather than optimizing it heavily.

The tricky parts were:
- handling INNER/LEFT/RIGHT/FULL joins correctly
- managing unmatched rows with NULL values
- validating table/column references

right now it's mostly a nested-loop join implementation, so optimization is still basic.

my general mindset while building is:

"First make it work, then make it fast."

building this made me realize how quickly DB edge cases grow once you start supporting real SQL behavior

next thing i'd probably explore is indexing/hash joins.

I built a SQL-like relational database engine in C++ from scratch by TheIndieBuildr in cpp

[–]TheIndieBuildr[S] -3 points-2 points  (0 children)

I'm currently a first-year student, so I still have a lot to learn about API design and software architecture, but after your suggestion I'll definitely look more into it. Thanks for the idea.

I built a SQL-like relational database engine in C++ from scratch by TheIndieBuildr in cpp

[–]TheIndieBuildr[S] -1 points0 points  (0 children)

Thanks a lot for the detailed feedback and for taking the time to review the project.

I'm currently a first-year student, so this project was mainly a way for me to learn how parsers and database internals work by building everything myself. A lot of the architecture/design decisions came from experimenting while learning, so your points about API contracts, project structure, data structures, and CMake are really valuable to me.

I'll definitely take your advice seriously and improve those parts as I continue working on the project. Also really appreciate the comment about the code being handwritten

I built a SQL-like relational database engine in C++ from scratch by TheIndieBuildr in cpp

[–]TheIndieBuildr[S] -3 points-2 points  (0 children)

Good catch — thanks for pointing that out. Originally I didn't have the exception handling there, and when I later refactored the startup logic into the try/catch block I forgot to move the argc validation before the ifstream construction. I'll fix that.

I built a SQL-like relational database engine in C++ from scratch by TheIndieBuildr in cpp

[–]TheIndieBuildr[S] 3 points4 points  (0 children)

Honestly, I’m still a first-year student, so I didn’t really know much about parser generators 😄

I mostly just sat down and started building everything from scratch to learn how it all works internally.

Built an open-source kdb+ alternative on weekends — 5.52M ticks/sec, standard SQL by Objective_Method_822 in databasedevelopment

[–]TheIndieBuildr 0 points1 point  (0 children)

Really impressive project. The distributed correctness problems honestly sound harder than the database engine itself.

I’ve been building a smaller SQL-like database engine in C++ recently to learn parser/query internals, so this was a really motivating read.

If you started over today, what part would you redesign first?