Design a Blockchain Based System
0%
Editorial Solution
System requirements
Functional
Capacity estimation
Traffic
API design
Client APIs
Database design
Block Structure
High-level design
Request flows
Transaction Submission Flow
Detailed component design
GATE: Consensus, How Untrusted Nodes Agree
Trade offs/Tech choices
PoW vs PoS
Failure scenarios/bottlenecks
Network Partition
Future improvements
Layer-2 Scaling Solutions
Table of Contents
System requirements
Functional
Capacity estimation
Traffic
API design
Client APIs
Database design
Block Structure
High-level design
Request flows
Transaction Submission Flow
Detailed component design
GATE: Consensus, How Untrusted Nodes Agree
Trade offs/Tech choices
PoW vs PoS
Failure scenarios/bottlenecks
Network Partition
Future improvements
Layer-2 Scaling Solutions
You transfer 1 ETH to a friend. Both wallets update instantly. But who decided that transfer was valid? No bank verified it. No central server processed it. Thousands of independent computers, many operated by strangers, all agreed your transfer was legitimate and recorded it permanently. The real challenge is not moving money between accounts. It is getting thousands of nodes that do not trust each other to agree on the state of a shared ledger, without any central coordinator.
Functional
Create and manage wallets: Users generate cryptographic keypairs that serve as their identity on the network. A wallet address is derived from the public key. The system tracks balances and transaction history per address. Unlike a bank account, no central authority issues or controls wallets. The private key is the sole proof of ownership, lose it and the funds are gone forever.
The numbers reveal a surprising truth: a blockchain's bottleneck is not storage or compute, it is consensus latency. The data itself is small. Getting thousands of nodes to agree on that data is the hard part.
Traffic
10 million users generating 1 million transactions per day gives roughly 12 TPS on average. During peak events (token launches, DeFi liquidation cascades, market volatility), traffic spikes to 100 TPS. The system targets 1000 TPS capacity to handle 10x peaks with headroom. 100,000 smart contract executions per day add computational load but not proportionally more storage, since contract calls modify state rather than creating new records.
Two layers serve two audiences. End users interact through a REST API that hides blockchain complexity, submit a transaction, check a balance, deploy a contract. Nodes communicate through a P2P protocol that handles consensus and block propagation. Mixing them would force wallet apps to speak gossip protocol and validators to parse REST requests.
Client APIs
POST /wallets: Generate a new cryptographic keypair. Returns the wallet address (derived from the public key) and the encrypted private key. The server never stores the raw private key. In a non-custodial design, the keypair is generated client-side and only the public address is registered with the network.
A blockchain has two storage layers that serve fundamentally different purposes. The chain itself is an append-only ledger, you only add blocks, never modify or delete. The state database is a mutable snapshot of current account balances and contract storage, rebuilt entirely from the chain if needed. This separation means the chain is the source of truth and the state database is a derived index.
Block Structure
1Block Header:
2block_number UINT64
3previous_hash BYTES32
4merkle_root BYTES32
5timestamp UINT64
6validator ADDRESS
7consensus_proof BYTES (signature or PoW nonce)
8
9Block Body:
10transactions[] List of signed transactionsSeven components, one rule: every state change goes through consensus. No shortcut, no fast path, no trusted node that skips validation. This is what makes the system a blockchain rather than a distributed database with extra steps.
API Gateway: REST and WebSocket endpoint for external clients. Accepts signed transactions, serves balance queries, handles contract deployment. The gateway is a stateless proxy that forwards to the local node. Multiple gateways behind a load balancer handle client traffic, but each gateway talks to one full node. The gateway validates request format but not transaction validity, that is the node's job.
Two flows drive the system. The transaction flow (user sends funds or calls a contract) touches every component from API to consensus to gossip. The balance query flow is local, fast, and reads only from the node's state database. Understanding both reveals where decentralization adds latency (transaction flow) and where it is invisible (query flow).
Transaction Submission Flow
"How do a thousand computers that do not trust each other agree on a single version of the truth?" This is the core interview question. Without consensus, each node has an independent database. With consensus, they share an authoritative ledger. The consensus mechanism is the single component that transforms a collection of replicated databases into a blockchain.
GATE: Consensus, How Untrusted Nodes Agree
Every blockchain design decision is a three-way tension between decentralization, security, and performance. Improving one almost always degrades another. The art is choosing the right balance for the system's use case.
PoW vs PoS
Proof of Work: Proven security model (Bitcoin has operated for 15+ years without a successful 51% attack). Anyone with hardware can mine, making it highly decentralized in theory. The cost is staggering energy consumption, Bitcoin uses roughly as much electricity as a medium-sized country. Block time is 10+ minutes for meaningful security, limiting throughput.
A blockchain is designed so that failures cause temporary slowdowns but never permanent data corruption. The redundancy built into every layer, every node has a full copy, every transaction is validated independently, means that losing any single component is invisible to the network. The dangerous failures are not crashes but Byzantine ones: nodes that actively lie.
Network Partition
The network splits into two groups that cannot communicate. Each group continues producing blocks independently, creating two competing chains. Transactions may be confirmed on one side and unknown on the other. When the partition heals, the consensus protocol's fork resolution kicks in: PoW picks the longest chain, PoS picks the chain with the most attestations, BFT halts entirely during the partition (no block is committed without 2/3+ votes).
The base chain handles secure, decentralized transaction processing. But the blockchain trilemma means the base layer alone cannot scale to global transaction volumes without sacrificing decentralization. The next frontier is pushing throughput off-chain while keeping the base layer as the trust anchor.
Layer-2 Scaling Solutions
Rollups bundle hundreds of transactions off-chain and submit a single proof to the main chain. Optimistic rollups assume transactions are valid and allow a challenge period (typically 7 days) for fraud proofs. Zero-knowledge rollups generate a cryptographic proof that all transactions are valid, verifiable on-chain in milliseconds. The main chain serves as the settlement layer, inheriting its security guarantees while processing 10-100x more transactions.
Try this problem yourself
Reading a solution is not the same as producing one under interview pressure. Design it on the whiteboard and get scored feedback.
0%
Editorial Solution
System requirements
Functional
Capacity estimation
Traffic
API design
Client APIs
Database design
Block Structure
High-level design
Request flows
Transaction Submission Flow
Detailed component design
GATE: Consensus, How Untrusted Nodes Agree
Trade offs/Tech choices
PoW vs PoS
Failure scenarios/bottlenecks
Network Partition
Future improvements
Layer-2 Scaling Solutions
Table of Contents
System requirements
Functional
Capacity estimation
Traffic
API design
Client APIs
Database design
Block Structure
High-level design
Request flows
Transaction Submission Flow
Detailed component design
GATE: Consensus, How Untrusted Nodes Agree
Trade offs/Tech choices
PoW vs PoS
Failure scenarios/bottlenecks
Network Partition
Future improvements
Layer-2 Scaling Solutions