17

There are a lot of articles describing how Ethereum is just another database, and a number of posts here on this site that talk about storing data on the blockchain itself (e.g., [1], [2]). However, my question is a bit more basic than those. Specifically, if a blockchain is just a database, then:

  1. What kind of database is this (e.g., relational database, nosql, registry-style key/value pairs, plain text, etc)? What any older technology can I look to for an understanding of how it works? This Quora question has answers that suggest both relational-style (by mentioning foreign keys) and key/value pairs, figured I'd ask here and see if I can get more consensus.
  2. How do I "read" a value from the database? How can I be sure I'm getting the most recent version of that (e.g., no transactions have taken place that update the value of this data)?
1
  • So it appears public Blockchain , Ethereum is NOT a database in the sense of a repository of sizable files (e.g. text, image files, etc.) At the most, it contains pointers to off-chain sources.
    – Misterkev
    Commented Aug 10, 2017 at 13:37

4 Answers 4

7

Blockchains are databases from a high-level view, but the underlying technology is different enough to make some assumptions inaccurate. An Excel file is also a database, but with characteristics unneeded/harmful for say, a NoSQL database.

The data "is" on every full node. That is, every client replicates the entire blockchain. This is indeed inefficient, and future development is aimed towards removing this requirement.

  1. The official specification for the state (that is, the set of all contracts and accounts and their storage and balance) is a Merkle Patricia Tree. However, an individual node may implement it internally in whatever way it finds best. (geth uses levelDB for example.)
  2. Every full node has its own copy of the blockchain. Reading consists of querying one's own node for the data. There's no guarantee that you have the latest block--an inherent limitation of blockchains. There are several ways for a good dapp to come with this environment--the primary is simply not to assume that the local latest block is the actual latest.
2
  • Thanks! I'm not quite sure what anything in (1) has to do with the question, though. Implementation aside, I'm still not clear on what types of data we're storing. To use the Excel example: Excel at its simplest is a tabular database with weak relational support, and the data is stored in individual cells in Excel worksheets. (Oversimplified for example... please don't nitpick here.) What type of data is Ethereum storing, and where does it put it?
    – eykanal
    Commented Dec 5, 2016 at 17:39
  • 4
    Ethereum essentially maps an address to a tuple containing the address's balance, nonce, "storage" and code. It's a bit more complicated than that, because each account has 2^256 storage addresses, with random access ability. The whole system is stored as a Patricia Merkle Tree, and the goal of the netwok is just to agree on the root of the tree Commented Dec 5, 2016 at 19:32
3
  1. It is a custom structure, not SQL anyways. It contains the previous hash, Nonce, Merkle tree root and the timestamp, very basically, but also may other informations about the block. You can look at the official wiki post for detailed information.
    1. You can read it by using the official javascript or c++ APIs, or more directly whith the JSON RPC API which is actually what the two official APIs do.
    2. Blockchains are numerous and most of them are trying to experiment on the blockchain structure and the transactions media, some have litterally thousands of sub-blockchains, some stick to only one that contains the transactions. The ethereum blockchain contains its transactions withinin the Merkle trees associated with each block.

Correct me if I'm wrong!

0

Blockchain has no finite state. It can reorganize itself, it can fork etc. No transaction can be considered 100% finite, but any block confirmation decreases chances of reorganizations.

So it is a completely new paradigm, it is more like a probabilistic database.

0

If you consider a database a series of transactions against a certain state, then the transactions themselves are the database. At its most basic level, a blockchain is a ledger--that is, a list of transactions. When I hear people say the blockchain is a database, this is what I think of.

Not the answer you're looking for? Browse other questions tagged or ask your own question.