nemr.app

BlockchainEngineering

How Blockchains Actually Work: A Developer's Mental Model

· 5 min read · by Elias Nemr

Skip the hype. A developer's mental model of blockchains: replicated state machines, hash-linked blocks, consensus, finality, fees and where smart contracts fit.

Blockchain explanations tend to fall into two camps: price-chart hype or cryptography lectures. Neither helps a developer who just wants to know what the thing is and what it's good for. Here's the mental model I find most useful, built from ideas you already know.

Start here: a replicated state machine

Forget "the chain" for a moment. At its core, a blockchain is a state machine replicated across many computers that don't trust each other. There is some state (account balances, contract storage), a set of rules for how transactions change that state, and a way for thousands of independent nodes to agree on the order of transactions so they all compute the same result.

Everything else — blocks, hashes, mining, staking — is machinery for answering one question: how do strangers agree on one ordered list of transactions without a central authority?

Transactions are batched into blocks. Each block includes the hash of the previous block, so changing any historical transaction changes that block's hash, which breaks the link in every block after it.

function makeBlock(prev, txs) {
  const header = { prevHash: prev.hash, txRoot: merkleRoot(txs), time: Date.now() };
  return { header, txs, hash: sha256(JSON.stringify(header)) };
}

This gives you tamper-evidence: you can't quietly rewrite history, because everyone else holds copies and will notice the hashes no longer match. Note what it doesn't give you by itself: it doesn't decide which chain is the real one. That's consensus.

Consensus: who gets to append the next block?

If anyone could add a block at any time, you'd have chaos. Consensus mechanisms pick who proposes the next block and make cheating expensive:

  • Proof of work: proposers burn computation to find a valid block. Rewriting history means redoing that work, which is prohibitively costly if honest participants control most of the hash power.
  • Proof of stake: proposers and validators lock up capital as a bond. Misbehaviour can be punished by destroying part of it ("slashing"), so cheating costs real money.

Both are ways of tying the right to extend the chain to something scarce. The trade-offs between them are about energy use, hardware requirements, speed and the specific attack models they defend against — which is why the details matter far more in a design review than in a headline.

Finality and reorgs: "confirmed" is a probability

Developers coming from databases expect a committed transaction to be final. On many chains, it isn't — at least not immediately. Two nodes can briefly see different chain tips, and the network later converges on one, discarding blocks on the losing branch. This is a reorganisation (reorg), and transactions in the discarded blocks may be reordered or dropped.

In practice this means you wait for a number of confirmations proportional to the value at stake, or rely on a chain with explicit finality (where, after a checkpoint, reverting would require provably destroying a large amount of stake). Any system that treats the first confirmation as irreversible is a bug waiting for a bad day.

Accounts versus UTXOs

There are two common ways to represent "who owns what":

  • UTXO model (Bitcoin-style): the ledger is a set of unspent outputs. A transaction consumes some outputs and creates new ones — like paying with banknotes and receiving change.
  • Account model (Ethereum-style): the ledger maps addresses to balances and storage. A transaction updates those entries — like a bank ledger.

UTXOs make parallel validation and certain privacy techniques easier; accounts make stateful programs easier to write. Neither is "better" — they suit different designs.

Smart contracts: deterministic programs on shared state

A smart contract is code stored on-chain that runs as part of transaction processing. Because every node must reproduce the same result, contracts have strict constraints that surprise newcomers:

  • Determinism: no random numbers from the OS, no wall-clock reads, no network calls. Everything must be derivable from chain state.
  • Metering: execution costs fees (often called gas) so nobody can run unbounded loops for free.
  • Immutability by default: deployed code usually can't be patched. Upgradeability patterns exist, but they reintroduce trust in whoever holds the upgrade key.
  • Public by default: state and transactions are visible to everyone. "Private" variables are only private to other contracts, not to observers.

That last point makes the contract code the product: bugs aren't patched, they're exploited. Reentrancy, integer overflow, access-control mistakes and unsafe external calls have each cost real projects real money. Treat contracts like safety-critical firmware: small, audited, heavily tested, with an emergency plan.

Fees and the mempool

Blocks have limited space, so transactions compete for inclusion. Pending transactions wait in a mempool; proposers typically prioritise those that pay more. This creates a fee market — and also opens the door to front-running, where someone who sees your pending transaction inserts their own ahead of it. If your application is sensitive to ordering (trading, auctions), design for it explicitly.

Oracles: the edge of the sandbox

Because contracts can't make network requests, anything from the outside world — prices, weather, sports results — has to be pushed on-chain by an oracle. That reintroduces a trust assumption at exactly the point the chain was meant to remove one. When you see "trustless", ask what the oracle's trust model is.

Keys are identity — and risk

Ownership on a blockchain is control of a private key. There's no "forgot password" button. Wallet UX, key management, social recovery and hardware signing are not side topics; they're where most real-world losses happen, usually through phishing and key leakage rather than broken cryptography.

When a blockchain is the right tool

A useful rule: if a single trusted party could run the database, you probably don't need a blockchain. A normal database is faster, cheaper, private, and easy to correct. A blockchain earns its cost when:

  • Multiple parties who don't trust each other must share one source of truth.
  • No single party should be able to alter or censor the record.
  • You need programmable assets or rules that anyone can verify and compose with.
  • Open, permissionless participation is itself a feature.

If none of those apply, the honest answer is usually "use Postgres".

The mental model in one paragraph

A blockchain is a replicated state machine whose transaction order is agreed by consensus among mutually distrusting nodes, made tamper-evident by hash-linked blocks, and extended with deterministic, metered programs. It trades speed, privacy and the ability to undo mistakes for credible neutrality and shared verifiability. Know which of those trades your project actually needs, and the rest of the ecosystem's jargon becomes much easier to place.

Elias Nemr is a software engineer who has built and shipped products across Blockchain, Finance, E-Commerce, AI, Energy and Indie Games. More about him →

Found this useful? Buy me a coffee

Keep reading