Build your own fast, persistent KV store
dinesh.wiki
dinesh.wiki
It's still a toy but I kept adding features.
I then kept working on it and added distribution with consistent hashing, rudimentary SQL joins, Cypher graph database queries and document storage. You can even query documents with SQL.
I didn't get around to changing the graph storage to be multimodal.
It takes very little code to write something with lots of features.
https://GitHub.com/samsquire/hash-db
There's an AVL tree that farleyknight wrote and a btree that I wrote that need to be integrated into it.
How is that word pronounced? If it's pronounced "tree", it clashes with the name of another data structure. But if it's pronounced "try", it clashes with the name of a reserved word in many languages.
The idea was independently described in 1960 by Edward Fredkin, who coined the term trie, pronouncing it /ˈtriː/ (as "tree"), after the middle syllable of retrieval. However, other authors pronounce it /ˈtraɪ/ (as "try"), in an attempt to distinguish it verbally from "tree".
(That word breaks my brain, too - the above is a coping mechanism.)
In the past I recall reading/hearing "trie-tree" (pronounced "try tree") as an ambiguity reducer, but I don't know how common that is now, or ever was.
https://github.com/codr7/whirlog
I've found that reinventing wheels is a great way to learn, even if you never use them.
https://github.com/mr-karan/barreldb/
Bitcask is an excellent paper that is not overwhelming to understand and offers a great stepping stone in building your own data stores. The simple yet powerful design of an append only file is eloquent and performant.
I’d love to read about more such implementations, if anyone has any recommendations.
https://en.wikipedia.org/wiki/Log-structured_merge-tree
https://en.wikipedia.org/wiki/Tracing_garbage_collection#Gen...
By the way, the course is built on top of Distributed System's lab: https://github.com/emichael/dslabs
If you need a fast and performant kV store stick to RocksDb or LevelDb. Don't reinvent the wheel. Most of performance comes from optimizing for OS and CPU.
The other storage engine riak could use was google's levellb.
At the time bitcask was as fast or faster than leveldb for most tasks. This was I think around 2010. I have no idea how it compares with a recent version of rocksdb, but at the time it was pretty fast.
I have set up this project in TDD fashion with the tests. So, you start with simple functions, pass the tests, and the difficulty level goes up. There are hints if you get stuck. When all the tests pass, you will have written a persistent key-value store.
Assuming the root node knows how to find the various things you are looking for (i.e. physical offsets to child nodes), this is how you can address the storage.
The trickiest part is finding the latest root node in adverse scenarios (i.e. plug pulled/partial write to disk). You can develop some 2-tier system where a 32-bit magic cookie is scanned for in blocks from back to front, and once it is encountered the relevant offsets are applied and the candidate attempts deserialization+checksum. No partial writes can be recovered in this scheme and wind up as wasted bytes in the log.
At some point I had intended to use this for a work project, but then SQLite came in and ruined my little party.
Designing Data-Intensive Applications has a VERY clear and understandable chapter about them. Once you've finished reading it, you'll have the tools to whip together a toy implementation for something like this.
Shameless plug, we've got an interactive Build your own Redis and Build your own SQLite module on CodeCrafters, which subscribes to the same learning philosophy
https://codecrafters.io/redis & https://codecrafters.io/sqlite
May be of interest to you
TIL about code crafters. Looks promising; I will check it out.
That distributed systems lab is what Georgia Tech's Distributed System lab[0] is based on, at least when I took the course back in 2021
[0] - https://omscs.gatech.edu/cs-7210-distributed-computing
[0] https://pragprog.com/titles/tjgo/distributed-services-with-g...
How fast can you store 10 million integers mapped to keys using this? 10 million strings? Doubles? other data types?