Does anyone know whether cockroachdb can be used as a decentralized database so that some stored information will be 100% transparent and will broadcast to every user of the database.
Thank you so much!
I don’t think cockroachdb has anything special for that (your requirement sounds like what a message queue would do), but if you wanted to use crdb, you could simulated it in your app level as a query that runs on a schedule (every 2 seconds or so), and that would go to the clients when it finds something.
@fmpwizard is right: we don’t currently support broadcasting a “change notification”. It’s on the roadmap, though! If you’re interested in following the progress, you can track https://github.com/cockroachdb/cockroach/issues/2656.
Thank you so much for your effort, but there is a built-in raft consensus algorithm. Is it the approach to decentralized mechanism?
The core devs may have a better answer but my understanding is that the use of raft isn’t something exposed to the user of the database (the apps we run), but instead it is meant to be internally used by crdb to do things like keeping certain number of copies of the data on several nodes to survive node failures.
For broadcasting information to a group of users, I normally use https://nats.io/ , normally the messages there are one sender one receiver, but there is an option to have multiple receivers get the same single message published to a topic
Not knowing much about your particular use case, I would do that, use nats for the broadcasting and then store the messages in crdb in case I need to reply them or if I need some kind of audit of all messages sent with date, etc
Thank you so much, Diego. I am just a imperial collage student doing
project relating to this, quite new to me to be honestly.
We have all been there (new to all these things), all the best on your project
Thanks a lot, that does inspire me! Could I ask a silly question about database? If I wanna validate a transaction from the upper layer, will I need to pick a node to deal with it? if so, what kind of work the node does to process it? For example, if person A is going to spend 50 pounds from his account, my system will try to validate whether his account has sufficient balance, so what I meant is that what is the process of validation?
Thank you so much for your time!
Thanks for the heads up on NATS, Diego. We have been doing our own PUB/SUB and or using MQTT for this kind of thing. NATS looks like it might be much better!
Sorry, off topic but it’s my cool find of the day.
If I wanna validate a transaction from the upper layer, will I need to pick a node to deal with it
No, crdb makes sure that all nodes give you the same answer, for the example of a person trying to spend money but checking that the balance is >= than 50, you use a transaction. You can google database transactions for more details on it, but the short version is, when you are inside a transaction, you can read, update, insert, delete data in order and the end result will be consistent, meaning, you can do your query to make sure that the balance is >50 (select query), then deduct 50 (update … set amount = amount - 50), and then you commit the transaction, only at that point, after the commit, the db will “really” update your row(s)
that means that is another part of your app was also trying to deduct 50, but both cannot be run to the end, because the person only had 60 in her balance, the second transaction will fail.