ToyKV teaser

Here’s a teaser of my followup to the build your own database index series. It’s the most minimal key value store you can write, and is extremely not useful. It does almost nothing you’d want an actual place you put data to do:

  • Doesn’t bother checksumming any data. Bit flips for the win!
  • Opens files every time it reads or writes them. Every. Single. Time.
  • Makes no attempt at all to compress data. Keys and values are just streamed to disk in all their bloated glory.
  • It’s an LSM “tree” with just one branch of SSTables.
  • And those SSTables are never compacted, and eventually you run out of them.

And it does none of those things so I have a chance to explain it in a reasonable number of words. For that purpose I think I’ve been successful. With a bit of code cleanup, it should be a decent pedagogical tool.

Here’s the main library code to give an idea of just how simple it is:

You can see how little data safety matters by (a) the complete lack of error handling, and (b) that the whole database has only seven tests. Put on your hard hats, and prepare for falling rocks 👷

But even with its general awfulness, I’m still excited about having written something that can store and read back stuff in a way that’s not completely trivial. More importantly, writing it has given me the foundation for learning the ways to write a better LSM tree data store.

While you wait for me to write about ToyKV, you can find the code at mikerhodes/toykv.

← Older
BYODI 5: plan, optimise, execute 🚀
→ Newer
S3 Express One architecture deep dive