MultiChain as a distributed database

+2 votes

I'd like to use MultiChain as a distributed database to store a variety of configuration and status information of a bunch of serves to avoid a single point of failure or setting up a database servers on each of the nodes with multi-master setup.

How would you configure MultiChain in this case?
asked Dec 6, 2015 by anonymous

1 Answer

0 votes

Thanks for your question. I'd be interested to understand a little more about your use case before giving really detailed recommendations. For example is your usage model having a data feed, which is written to by one or more parties, then read by one or more parties. Or something else?

But in a general sense I would recommend using transaction metadata (see for example the sendwithmetadata API) in which you can store any general-purpose information, which will then be replicated to all other nodes.

answered Dec 6, 2015 by MultiChain
This is a network of test machines for software and the information that is shared would be the server status of each machine. Also information about available builds would be shared among the machines. Then they could be shared among the test machines e.g. using BitTorrent.

So basically each of the servers in the network share information (so each server should only be able to update its own information), but everybody should be able to read everything.

I could use e.g. PostgreSQL BDR for this, but that sounds a bit heavy-handed and I'm not sure how maintenance-free that would be.
Thanks for your reply. So first I'll be honest with you - it's not yet really easy to do this with MultiChain. But it is possible.

First set up with blockchain with all the nodes. To keep things simple, keep one address per node that it uses for its feed, and use the grant API to make sure they all have connect, receive, send permissions. You might want to have more than one administrator node for redundancy. But don't use the admin address for the feed.

Then use the importaddress API to add each node's address to every other node, without the corresponding private key. This lets each node watch and retrieve the transactions for that address. More info on the API is here:

Now each node can send transactions to itself using sendwithmetadataform, using the feed address, with 0 amount and whatever metadata you like in hexadecimal. These transactions will be visible to other nodes using the listtransactions API, and you get then get more information about them (by txid) using getrawtransaction.

FYI the next alpha will include a better API listaddresstransactions for retrieving the list of transactions which is relevant for a particular address.

Anyway I hope this helps - if this is a popular use case over time we will add APIs to make all of this much easier - with calls like createfeed, publishtofeed, read feed :)
This was very helpful but I was wondering if there is a better way to approach this exact problem with the new APIs that have been added in the beta version?
Yes, you should definitely use streams for this. You can get the basic idea of how streams work by going through the tutorial: