ToyDB: Distributed SQL Database in Rust
github.com
github.com
This is exactly what I was hoping to find. This is great!
But I can read source code (though I'll have to learn Rust) and this is amazing work.
I think that all the state management problems and solutions in all languages/frameworks (react, swiftui, elm etc etc) would be better implemented as a database with changefeeds [0]/ change data capture [1].
The advantage compared with something like Redux is that it's more general. You don't need to implement an enum with a case for each action and then have a big dispatcher.
All your update logic would be a big switch statement on change feed from the database which would handle all the logic.
The fundamental problem of state management is as follows, if a leaf view changes some data, how does some view higher in the hierarchy learn about this?
I think that this solves the problem better than alternatives or the observer pattern.
Ideally the API would be something like LINQ methods in order to avoid parsing SQL.
I'm still trying to figure out if this would work.
You seem to have thought a lot about this, but I don't understand the distinction you're making and I'd appreciate help squaring this up in my mind.
In the case of Redux, you have the current state, you have actions and selectors (from a CQRS perspective, an action = a command and a selector = query), and you have reducers that apply the actions to the state then update/notify the selectors. How is this different than what you stated? Are you just suggesting the removal of actions and directly changing the state, like reactive programming, with a changefeed being generated as a side effect of manipulating the state? In that case, how do you handle situations where the update requires knowledge of the current state? Won't you need to read in the current state, apply changes, and then write back? And at some point you will want to be able to pass parameters so you can combine some input (eg. the updated user's last name in a text box) and the current state (the user's first and last name) to update another state property (the user's full name). At that point you've essentially re-implemented the concept of actions and reducers.
At the end of the day, if you have a relational model and you want to allow subscriptions arbitrarily on the object graph, something somewhere will have to traverse the tree of the object's parents and apply a notification to them, right?
Or you will have to only allow replacing object changes/subscriptions at a flat level, which is a document-based model rather than relational. In that case, you can filter the notification stream as an optimization for the clients, but the entire document would require replacement on every update. You can do an additional optimization and allow patches of the object, and use diffing to not notify if a specific property was unchanged after the state update, but these are all implementation details.
I don't think this is a fundamental problem of state management, more-so a restriction of state management when dealing with state expressed as relational objects, and one of the reasons document databases are easier to reason about.
Bringing this back around to state management frameworks like Redux, each Redux store is essentially a single document and selectors are filtered notifiers of changes.
This project sounds interesting - you should make a blog post about your prototype database with some more details, I would love to read it and see some of the code!
In the Rust world, Salsa operates on similar principles: https://salsa-rs.github.io/salsa/
Personally I believe this pattern has totally solved the problem of responding to changes in state, and its use-cases are just beginning to be explored
I utterly fail to see the point in reimplementing it in some other language.
Innovate in databases - yes please - but "rewrite" - why?
Not being able to use battletested libraries written in plain C (e.g. sqlite) sounds like a hugh mark against rust as a systems programming language.
Is using C libraries an actual issue or just an aesthetic grumble?
Is software that is always evolving battletested ? A new version could break something.
I'm aware that sqlite has one of the best test suite in all of open source, I just wonder if something that was "battletested" is still battletested after a new release.
Introducing a buffer overflow in a small unused corner / edge case of the feature set allows an attacker to fully compromise the process, and it's thus a problem affecting a 100% of the users.
Introducing a behavioral bug in the same unused corner / edge case, will affect only a very small number if people (possibly none)
Also, with using SQLite's amazing test harness, it might even make sense to claim that the Rust re-implementation is of similar quality in terms of (lack of) bugs.
But, yeah, "cloning" projects is losing proposition (even more if open source). I wish a sqlite-like on rust? yeah, but not a clone, but in spirit (exist so much we can improve with rdbms!)
AYATAINWK?
Are You Aware That Acronym Is Not Widely Known?
Let's not forget that:
1. new programming languages bring excitement, creative destruction, and yes, lots of hobby projects that don't turn into battle-tested products. I'm ok with that.
2. rewriting is not the same as re-envisioning. See the comment above. SQLite was a starting point for inspiration, not the destination.
Also, we should not conflate an underlying technology with the hype around that technology:
a. Just because there is a lot of hype around Rust does not mean the advantages of Rust should be overlooked
b. Some highly-praised technologies deserve the praise. Yes, sometimes even the cynics are wrong.
How much you have to sacrifice, and how linear the scaling is, of course are important quality metrics of distributed systems. In multi-writer optimistic-locking sync-at-commit systems (eg Galera) in case of no conflict, it's possible to have the multi-node throughput exceed the throughput of the single-node version.
In practice even this ToyDB is likely able to serve requests in a degraded state (probably as long as the Raft leader's timer does not expire, and if there's a quorum of nodes they can reelect a leader). And it seems that if a node falls out of sync it will automatically rejoin and try to replay the logs. (As long as they are available of course.)
https://github.com/erikgrinaker/toydb/blob/master/docs/archi...
https://www.youtube.com/watch?v=hUd_9FENShA
https://blog.acolyer.org/2014/11/07/highly-available-transac...
FYI, recent information and progresses for TensorBase:
1. TensorBase(TB, for short) is not an reimplementing or clone of ClickHouse(CH, for short). TensorBase just supports the ClickHouse wire protocol in its server side.
2. TB's in-Rust CH compatible server side is faster than that in-C++ of CH. TB enables *F4* in the critical writing path: Copy-Free, Lock-Free, Async-Free, Dyn-Free (no dynamic object dispatching).
The result of TB's architectural performance: the untuned write throughput of TB is ~ 2x faster than that of CH in the Rust driver bench, or ~70% faster by using CH own ```clickHouse-client``` command. Use [this parallel script](https://github.com/tensorbase/tools/blob/main/import_csv_to_...) to try it yourself!
3. Thanks to the Arrow-DataFusion, TensorBase has supported good parts of TPC-H. [Untuned TPC-H Q1 result here](https://github.com/tensorbase/benchmarks/blob/main/tpch.md).
4. In simple (no-groupby) aggregation, TensorBase is several times faster than ClickHouse. [Benchmark here](https://github.com/tensorbase/benchmarks/blob/main/quick.md).
5. For complex groupby aggregations, recently we help to boost the speed of the TB engine to the same level of ClickHouse(not released, but coming soon).
6. TB will soon supports MySQl wire protocol, distributed query, adaptive columnar storage optimization... Watch [issues here](https://github.com/tensorbase/tensorbase/issues)
Finally, it is really great to build an AP database in Rust. Welcome to join!
Disclaimer: I am the author of TensorBase.
https://github.com/spacejam/sled
It’s surprisingly mature and the person behind it is very committed to the project.
Now building a Git player - basically watch a Git repo history unfold like a movie, for learning purposes [1].
Please ping me if you have some ideas, looking for learning peers.
but i wonder what if the same db was written in c++, would it get a post in HN?
However if it was just another DB.. especially one competing in an area no one really feels deficient, prob not.
Remember when clojure was going to take over the world?
Rust has some ideas that are pretty easy to see as to why it guards developers. It is not an easy language. It is surely a systems language and allows you to dig deeper into every aspect. You can roll your own implementation for anything to fit the need - want async in resource constrained platforms? Go ahead, write it.
But the guards are helping you think code that has less errors. It is an idea built into the language. But it is not the only thing* that sells it - the tooling is fantastic for systems language. The community is second to none. It is 10 years old now and only getting started - Linux, Microsoft and other big camps are giving it a chance - this has not happened in languages history at this level other than C/C++.
So yeah, give it a try and you will see why.
Do people excited about the new thing go over the top and upvote anything even tangentially related to it? Yes, I think you need to admit they do. Is that the worst thing in the world? No, certainly not.
In Rust, most talks I watch are tiny games, graphics and visualizations, emulators, language interpreters, some web (every language must it seems), experimental databases, kernels, lots of rewrites of other system software... Almost nothing I see in general is production focused, forget enterprise.
These are all from learners, hundreds of people falling in love with the language and the community. I have been in software for almost 2 decades, 15 years of them professionally. I have not seen this in a language that is also slowly going mainstream. Maybe I am wrong, but I am willing to bet a good chunk of my next 10 years to Rust.
Rust will not replace lots of code in Python (my main language), for example. Taking parts out and optimizing them in C++ is something I would have never done. I would do it in Rust. That gives a systems language huge appeal to tons of developers from the top 10 non-systems languages.