Blockchain vs database
Suggest an editThe previous lesson built up a blockchain from scratch. A reasonable reaction at this point is "interesting, but isn't that just a database?" Structurally, yes. But a blockchain has no operator that everyone trusts, and its differences from a database follow from that.
Both store records, and almost everything else differs
A blockchain and a database both store records, let you write new records and read existing ones, and have to handle many users at once. Both also apply a bundle of changes, called a transaction, completely or not at all, so money is never debited from one account without being credited to another. This property is called atomicity. If a blockchain call would do five things and the fifth one fails, the first four are unwound and the whole call has no effect on the chain's state.
Almost every other property they have is different, and the differences have one cause. A database has an operator, one party that runs it and that its users have to trust. A blockchain is built for parties who don't trust each other, so it has no operator at all.
Walk down the rows, and almost every cell on the database side describes flexibility, convenience, and speed. Almost every cell on the blockchain side describes constraint, public exposure, and the absence of a controlling party. The sections below show how these constraints follow from having no operator.
Nobody can be trusted to edit the past, so the chain is append-only
In a normal database, the four basic operations are create, read, update, and delete. Update and delete let you change or erase the past, and a database needs them. You change a row when a user updates their profile. You delete a row when a user closes their account. The operator decides who is allowed to do that.
A blockchain has nobody to give that right to, because whoever could edit the past would have to be trusted by everyone else. So it has only two of those four operations. You can write new entries and read any entry, current or historical. You cannot update an entry or delete one. The hash links from the previous lesson enforce this, because an edited copy stops matching everyone else's.
A record like this is called a ledger: an append-only record of events, the format banks and accountants have kept for centuries, where entries are only ever added and the earlier history stays intact. A blockchain is a ledger built to run without a trusted keeper.
This sounds limiting, and in most use cases it is. It pays off where the ability to prove "this happened, exactly this way, and has not been changed since" is more valuable than the ability to keep things tidy. Once a record is in a block deep enough in the chain, no party in the system can convincingly claim it isn't.
Every node checks the records, so every record is public
With no operator to vouch for the data, every node checks every record itself, and it can only check what it can read. So every record in a public blockchain is readable by every node, and through the nodes by every user, and ultimately by anyone in the world who wants to look. Open any block explorer (a website that displays the contents of a chain in human-readable form) and you can see every transaction that has ever happened, every balance of every account, every smart-contract call, every event.
There is no private mode and no operator who can hide some rows from some users. The only thing that protects a user's identity is the fact that an address on the chain is a meaningless-looking string of characters rather than a name.
This is a feature for some use cases and a non-starter for others. A public blockchain is the worst possible place to store medical records, internal company data, or anything subject to data-protection regulations. It's an excellent place to store the history of a lending application such as Aave, because anyone in the world can check what the application has done by reading the chain directly, without taking anyone's word for it.
Every node keeps a full copy, so the network is durable and slow
A traditional database lives on one server or one cluster of servers, run by one party. It can keep extra copies, but the operator has to set them up, and the copies follow one main server.
In a blockchain every full node holds the entire history, and no copy is the main one. If half the nodes in the network went offline tomorrow, the other half would continue running the chain and nothing would be lost. The data is durable because it exists in thousands of places at once.
The price of this durability is speed and cost. Every node has to validate every block, store the whole chain, and keep up with every new transaction, so the network can never go faster than the slowest agreement step among its participants. A database handles millions of writes per second at fractions of a cent each. A public chain handles a few to a few thousand per second, at cents to dollars per write.
Use a database unless the parties don't trust each other
A normal database is the right choice for almost every problem. It's faster, cheaper, flexible, and private by default, and it has decades of tooling and operational knowledge built around it.
A blockchain is the right choice when you need to prove things about state to parties who don't trust each other, or when you can't have a single operator. It's also right when transparency is more valuable than privacy, or when the cost of a single point of failure is unacceptable. Bitcoin is such a case: two strangers exchange value directly, with no operator in the middle, as The Bitcoin design philosophy lesson explains. The next several lessons explain how a network with no operator reaches agreement.