TransWikia.com

Is it possible to create a relational data schema with multiple tables on blockchain?

Stack Overflow Asked by user3848207 on November 12, 2021

Blockchain has been described as a form of database. So far, most blockchain applications seem to involve blockchain as a one-table database.

Is it possible to create a data schema with multiple tables, one-to-many relationship like a relational database on blockchain? If not, why?

2 Answers

Using the blockchain structure directly? No. However, a blockchain ledger serves very similar purposes as a write-ahead logging (WAL). Quoting from wikipedia: "a family of techniques for providing atomicity and durability (two of the ACID properties) in database systems".

WALs and distributed ledgers are just ways of registering a sequential set of events, where order matters. The main difference is that a WAL does not contain the whole history of events.

The way you construct SQL or any other type of database over blockchain, is by using the ledger as a WAL for SQL instructions. Since the ledger contains the whole history of events, you can always reconstruct the SQL database by executing the history in the same order.

Answered by shumy on November 12, 2021

If I understand your question, you're asking, "can I treat a blockchain just like a normal relational database, and execute queries?" I assume you basically want a database, with the benefits of "immutability" and decentralization. Technically, the answer is yes, but economically and practically, there are a few things to consider.

  1. Immutability of blockchain is only really achieved if there really is decentralization and a strong decentralized consensus mechanism. For example, Bitcoin has been immutable because there is a lot of distributed hash power around the world, and a 51% attack would be prohibitively expensive. Smaller networks like Bitcoin Gold, can (and were) attacked because they don't have enough hash power to resist an attacker. So you need to make sure you are resistant to this.
  2. If you want to use the blockchain as a database for arbitrary storage, there has to be an economic incentive for users to store strangers' data. There have been many notable blockchain projects attempt this without as much adoption as previously hoped. This is in part because the economic incentive is not great enough. The only incentive Bitcoin users (miners) have to store the block data is to make sure the next mined block will be valid (if they don't store the data, they might mine an invalid block unknowingly because they can't properly validate the transactions).
  3. The technical implementation of this depends on what you are trying to accomplish. If you want to be able to query the blockchain like a database (without necessarily being able to store arbitrary data) these solutions already exist. Different node implementations can use whatever language, storage mechanism, operating system they want, as long as they can communicate and follow the consensus rules. The block data can be stored in a flat file, SQL, noSQL, whateverSQL, the node application just has to be able to read, write, and validate the data. The thing to optimize for here is speed. Since full tx validation requires the entire blockchain, this can be very slow if the database lookups are slow.

Blockchain was invented as a solution to decentralized consensus, and cannot really be taken out of the context it was invented in, which requires not only a technical implementation, but an economic incentive for usage.

Answered by JBaczuk on November 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP