Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 41 ยท Using Blockchains in Practice

Scaling: Layer 2, Rollups and Sharding

Why blockchains process few transactions per second, the scalability trilemma, and how payment channels, rollups, sidechains and sharding help, with live models.

A busy blockchain gets expensive. Fees rise because many people compete for a small, fixed amount of block space. The obvious fix, "make blocks bigger and faster", has a hidden cost: every full node must download, verify and store everything, and the bigger the load, the fewer people can afford to run a node. If only data centers can run nodes, you have rebuilt a centralized system with extra steps.

Scaling means finding ways to handle more transactions without giving up the properties that made a blockchain worth using. This lesson explains the limits, the trilemma behind them, and the main approaches: payment channels, sidechains, rollups and sharding.

How many transactions per second?

Throughput is simple division: the space or gas available per block, divided by the cost of one transaction, divided by the block time.

Python Throughput limits as arithmetic

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A few to a few hundred transactions per second is tiny compared with payment networks that handle thousands. And the last line shows why bigger blocks are not free: at 1,000 tx/s every full node would add several terabytes a year.

The scalability trilemma

Blockchain designers often describe three goals that pull against each other:

  • Decentralization: anyone with modest hardware can run a node and verify everything.
  • Security: attacking the network is very expensive.
  • Scalability: the system handles many transactions cheaply.

You can improve two easily. A small group of powerful validators gives speed and security, but little decentralization. The challenge is to improve scale without raising the cost of verification for ordinary participants. Nearly every technique below does this by moving work off the base layer (called layer 1, or L1) while keeping the base layer as the place where disputes are settled.

flowchart TB
    L2["Layer 2<br/>many transactions, cheap"] -->|"compressed data or proofs"| L1["Layer 1<br/>settlement, security, data"]
    L1 -->|"final truth"| L2

Layer 2 does the bulk of the work; layer 1 records the results and resolves disputes.

Payment channels

Two people who pay each other often do not need every payment on chain. A payment channel works like a bar tab:

  1. Open: both lock coins in a shared on-chain account (a 2-of-2 multisignature) in one transaction.
  2. Pay off chain: every payment is a new agreed balance, signed by both, with an increasing sequence number. Nothing touches the blockchain.
  3. Close: either side submits the latest signed balance, and the funds are paid out.

The risk is cheating: someone could submit an old balance that was better for them. So closing starts a challenge window; the other party can respond with a later state, and the contract always honors the highest sequence number (real systems such as Bitcoin's Lightning Network additionally penalize the cheater by letting the victim take the whole channel, and use "watchtowers" so an offline user is still protected).

Python A payment channel and a cheating attempt

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Channels are excellent for frequent payments between known parties, and routing across a network of channels extends them to strangers. They do not help with general smart contracts that many users share.

Sidechains

A sidechain is a separate blockchain with its own validators and rules, connected to the main chain through a bridge: assets are locked on one side and a matching representation is minted on the other. Sidechains can be fast and cheap because they make different trade-offs, but their security is their own. If the sidechain's validators collude or its bridge has a bug, funds on the main chain's lock can be lost, and bridges have been among the most attacked pieces of the whole ecosystem (see Smart Contract Security Pitfalls).

Rollups

A rollup executes transactions off the base layer but posts the transaction data (compressed) to layer 1. Because the data is public on L1, anyone can reconstruct the rollup's state and exit with their funds even if the rollup's operators vanish. This inherits much of L1's security, which is why rollups are the main scaling path for Ethereum.

flowchart LR
    U["Users"] -->|"transactions"| S["Sequencer<br/>orders and executes"]
    S -->|"batch + new state root"| C["Rollup contract on L1"]
    C --> V["Check: fraud proof<br/>or validity proof"]

The sequencer batches thousands of transactions into one L1 submission; the L1 contract decides whether to accept the result.

The two families differ in how L1 knows the batch was computed correctly:

Optimistic rollup Zero-knowledge (validity) rollup
Idea Assume the batch is right unless someone proves otherwise Attach a cryptographic proof that the batch is right
Check on L1 A fraud proof, only if challenged A validity proof, always verified
Withdrawal delay A challenge window, commonly around a week Minutes to hours, once the proof is accepted
Cost Cheap to produce batches Proof generation needs heavy computation

Zero-knowledge proofs let one party convince others that a computation was done correctly without redoing it (Privacy and Zero-Knowledge Proofs). Their real implementations are far beyond a Python toy, but the optimistic idea can be modeled completely: the operator posts a claim, and a watcher recomputes it.

Python An optimistic rollup with a fraud proof

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The last line is the weak spot of the optimistic model: it relies on at least one honest watcher being online during the window. That is the price paid for not proving every batch.

Why batching makes transactions cheaper

Layer 1 charges a fixed overhead for each submission, plus a small amount per transaction's data. Spreading the overhead across thousands of users is where the savings come from. The figures below are illustrative, not measured.

Python Cost per transaction versus batch size

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The cost per transaction falls steeply with batch size and then flattens near the per-transaction data cost. That floor is why cheaper data availability (for example, Ethereum's blob space introduced in 2024) matters so much for rollups.

Trade-offs to remember: the sequencer that orders transactions is often a single operator today (it can delay or censor you, though rollup designs include a way to force transactions through L1), and moving assets between rollups takes extra steps.

Sharding

Sharding splits the network's work so that each node handles only part of it. Execution sharding divides the state: each group of validators processes only its shard's transactions. It is hard because transactions that touch several shards need coordination, and a small group of validators is easier to attack, so shards need random assignment and rotation.

Ethereum's plan changed over time. Instead of many execution shards, it focuses on rollups for execution and on data sharding: spreading the storage and availability of rollup data across validators, who check small random samples of it rather than downloading everything. Some other blockchains do shard execution directly. Either way, the principle is the same: split verification so that no ordinary node must process the whole load.

Choosing an approach

Need Good fit
Many tiny payments between a few parties Payment channels
General apps with L1-level security Rollups
Independent, specialized chain with own security Sidechain or app-specific chain
More base-layer capacity Larger blocks (with decentralization costs) or sharding

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why not simply make blocks much bigger to scale?

    Decentralization depends on cheap verification. If running a node needs data-center hardware, fewer people can independently verify the chain.
  2. 2. In a payment channel, what stops someone from closing with an old balance?

    Every update has a higher sequence number signed by both. The counterparty can respond with the latest one, so an outdated state loses.
  3. 3. How does an optimistic rollup handle correctness?

    Batches are accepted unless a watcher proves fraud during the window, which is why withdrawals can take around a week.
  4. 4. What is the main security difference between a sidechain and a rollup?

    With a rollup, anyone can rebuild the state from L1 data and exit. A sidechain's safety depends on its own consensus and bridge.
  5. 5. Why does cost per transaction fall as rollup batches grow?

    Each submission has a fixed cost on L1. Dividing it by thousands of transactions leaves mostly the small per-transaction data cost.

Summary

  • Throughput is limited by block space (or gas) per block time, and bigger blocks make nodes more expensive to run.
  • The scalability trilemma: improve scale without hurting decentralization or security, usually by moving work off layer 1.
  • Payment channels move many payments off chain, with open and close transactions plus sequence numbers to defeat old states.
  • Sidechains are separate chains with their own security, linked by bridges.
  • Rollups execute off chain and post data to L1; optimistic rollups use fraud proofs and a challenge window, zero-knowledge rollups use validity proofs.
  • Batching shares fixed L1 costs, and sharding splits data or execution so no node handles everything.

Next: Privacy and Zero-Knowledge Proofs.