How to Scale an Ethereum Dapp

Bitcoin has one use-case only, i.e. enabling people to pay using digital currencies in a disintermediate peer-to-peer (P2P) network. However, Ethereum distributed apps (DApps) have enabled blockchain start-ups and developers to focus on many other use cases.

The Ethereum blockchain platform has thus enabled a wider adoption of, and interest in, the promising blockchain technology. However, if you look at the “State of the DApps” website, you will notice that even the most popular DApps barely attract just over a thousand ’Daily Active Users‘ (DAU)!

If you are an Ethereum developer trying to launch your killer DApp, this statistic is of some concern to you. What can you do to attract those millions of daily users that the centralized apps routinely attract?

We need to scale Ethereum DApps, and that‘s the answer. Ethereum‘s 13 transactions per second (TPS) just doesn‘t stack up well with the thousands TPS or more centralized apps. Read more about this unfavorable comparison in “Scaling Ethereum to Billions of Users”.

Scaling Ethereum DApps is important for you to attract those millions of users, hence I explain how to scale an Ethereum DApp in this article. Let‘s cover some basics first.

Contents

What is an Ethereum DApp?
Decentralization and security overshadow scaling Ethereum DApps
Ethereum sidechain: #1 of Ethereum blockchain scaling tips
Plasma: # 2 among potential Ethereum scaling best practices
“Casper Protocol”: The 3rd strategy to scale Ethereum DApps
Raiden Network: 4th option to scale Ethereum DApps
Sharding: the 5th Ethereum blockchain scaling tip

What is an Ethereum DApp?

An Ethereum DApp is a web app, but with the following distinct characteristics:

  1. You must run it on a decentralized blockchain;
  2. While you can code the front-end in any language, the backend code must be smart contracts running on a decentralized blockchain;
  3. You need to use open-source code for an Ethereum DApp;
  4. The user community decides any future change to the DApp via a consensus mechanism;
  5. It executes in an autonomous manner;
  6. A DApp must store data in a decentralized blockchain following cryptographic standards;
  7. DApps must use a crypto token and you must create that token following standard cryptographic algorithms;
  8. No one user can own a majority of crypto tokens because that will allow the user to control the future of the DApp.

Read more about what distinguishes a DApp from a centralized web app, in “How To Convert Web App Into A DApp”.

You have already noticed the stress on decentralization and security, didn‘t you? That brings me to the question of why Ethereum DApps don‘t scale.

Decentralization and security overshadow scaling Ethereum DApps

Why do blockchain-crypto start-ups flock to the Ethereum blockchain platform? It‘s the decentralization! A P2P network without a central administrator allows buyer and seller to directly transact without a middleman.

Check out how Storj.io has opened the cloud storage market to commoners. You can put your excess storage up for rent and earn their crypto token STORJ. This is possible because the Ethereum blockchain offers decentralization. Read more about how such decentralized cloud storage networks work in “How To Build A Decentralized Cloud Storage Solution Like Storj.io”.

Download Our Project Specification Template

Such decentralization makes the network permanent because even if hackers destroy one server, the system exists in other servers! However, this decentralization requires that every node on the Ethereum blockchain network store every transaction and every block. With the Ethereum network growing at a fast pace, every node is storing an ever-increasing amount of data!

Also, consider that Ethereum uses the ’Proof of Work’ (POW) consensus algorithm for transaction validation. This requires miners to solve a complex cryptographic puzzle to a solve a new block, which requires very high computing power.

The Ethereum community increases the complexity of the puzzle periodically, hence miners will need to use even more computing power in the future. Here too, every node must validate transactions and that a miner has indeed solved a block. Read more about how POW works, in “Proof of Work vs Proof of Stake Comparison”.

The more the network grows, the harder it is for hackers to stage a “51% attack” by capturing the majority computing power. Ethereum blockchain network has never been hacked. The Ethereum DAO hack you hear about was all about exploiting a bug in a smart contract that was running on top of the Ethereum blockchain.

However, this decentralization and security have made it difficult to scale the network! The more the Ethereum blockchain grows, higher will be the amount of data each node must store. Also, more nodes will need to participate in validating each transaction. We call it the “Blockchain Trilemma”, and you can read about it in “Solving the Blockchain Trilemma: Decentralization, Security & Scalability”.

You have good news! There are researches underway to determine how Ethereum will scale, and I will cover a few such key efforts.

Ethereum sidechain: #1 of Ethereum blockchain scaling tips

In this guide on how to scale Ethereum DApps, I will first explain the use of a sidechain blockchain. This strategy to scale Ethereum DApps works on a fundamental premise. The premise is that not all DApps require the same level of security.

Consider a DApp where you will allow transfer of thousands of Ethers. Obviously, hackers have high incentives to attack such a DApp. Compare that with a social media DApps, where users send messages and may spend fractions of a new crypto token for each message. The economic value is less, hackers won‘t consider it lucrative.

The concept of an Ethereum sidechain asks you to first determine what level of economic value your DApp has and decide on a security model for it. Now, based on security requirements, you set customized rules for your DApp. Read more about this differentiation in “DAppChains: Scaling Ethereum DApps Through Sidechains”.

For e.g., you will likely use the tamper-proof POW consensus algorithm for a high-value DApp and run it on the Ethereum mainnet. However, you can use a ’Proof of Stake‘ (PoS) algorithm for a low-value DApp and run it on a different blockchain.

You can run this lower-risk DApp on a ’Sidechain‘. A sidechain is just another blockchain that‘s attached to the main blockchain. A mechanism called ’Two-way peg‘ establishes this connection between these two blockchains.

The ’two-way peg‘ process works as follows:

  1. You send your Ether on the mainnet to a specified address. The coins are locked there, and you can‘t use them.
  2. A confirmation message is broadcast in the blockchain after the transaction completion, and a ’cool-off‘ period follows.
  3. Your DApp uses a different token and a different blockchain. There is a predetermined exchange rate between Ether and your token.
  4. Based on this exchange rate, the mainnet transfers an equivalent number of tokens to the other blockchain.
  5. You work with your DApp on your separate blockchain, and when you are done, you transfer back the remaining tokens to the mainnet.
  6. A similar exchange happens, and a confirmation message is broadcast.
  7. Note your DApps‘ blockchain is different from the mainnet, and you can customize rules there, for e.g. you can use a PoS algorithm if your DApp doesn‘t need POW.
  8. Computations of your DApps are offloaded into the sidechain, thus you avoid congesting the mainnet.

Read more about how sidechains work, in “What are Sidechains?”.

A blockchain start-up called the “Loom Network” uses a term ’DappChain‘ for sidechains that run DApps. Their design principle is one DApp per DappChain.

They offer a ’Platform as a Service’ (PaaS) for building DApps, and as part of that, they have the Loom Software Development Kit (SDK). You can use it to easily build your scalable DApps on DAppChains.

I had earlier referred to this promising start-up in “How to Build a DApp Game App Like CryptoKitties?”, because they also have their ’Unity SDK‘ using which you can build blockchain-based games. You can use their SDKs to scale game apps too.

Plasma: # 2 among potential Ethereum scaling best practices

Think of Plasma as the approach that will allow you to create a ’Child‘ blockchain on top of the Ethereum mainnet. The child blockchain will enable transactions and associated computations in its‘ network, and these won‘t use the Ethereum mainnet.

While you can run your DApp on a Plasma child chain and execute your transactions, you don‘t broadcast every transaction in the mainnet. You only periodically broadcast a transaction in the mainnet. This can provide a snapshot of the child blockchain transactions in that period.

Read How We Helped a Marketing Company to Build a Back-Office Custom Ads Dashboard

It decongests the mainnet, besides, you can set your customized rule for your Plasma child network. For e.g. you can use the PoS algorithm instead of the POW that‘s running on the mainnet.

Plasma is quite like the ’Lightning Network‘ of Bitcoin, and Joseph Poon, a co-creator of the Lightning Network has worked on Plasma too. Read more about the Lightning Network in “What is the Lightning Network?”.

Plasma can offer the following advantages:

  1. The mainnet acts as the ’Root’ blockchain and still provides the underlying security of a fully decentralized blockchain.
  2. Plasma will allow a child-chain to have its‘ own child-chain, and hence the overall network can resemble a tree structure.
  3. The root blockchain gets to work only when broadcasting the summary transaction, or when there is a dispute among different child-chains.
  4. Each Plasma child-chain sets its‘s own customized rules.
  5. Users of a Plasma child-chain can use the “Plasma Exit” mechanism. If they suspect foul play in a Plasma child-chain, they can withdraw their funds and return to the mainnet with those funds. They need to submit “Exit” transactions to the mainnet to do this.
  6. Since each Plasma child-chain can do their own complex calculations, it will allow significant scalability.

Plasma has a potential disadvantage. Suppose a lot of foul play is going on in the child-chains, and many users want to simultaneously exit those chains. Such a sudden spike of transactions can impact the Ethereum mainnet.

However, the “Plasma Exit” mechanism also has a “Challenge” period, allowing another user to dispute a claim. In case a sudden spike in “Exit” transactions, the community can decide to extend the challenge period to handle the load on the mainnet better.

Read more about Plasma in “Explained: Ethereum Plasma”. This solution is still under development, and a release date isn‘t announced yet.

“Casper Protocol”: The 3rd strategy to scale Ethereum DApps

Ethereum’s planned “Casper Protocol” is much more than just scaling Ethereum DApps or for that matter the Ethereum blockchain. It has a wider scope; however, it will help to scale Ethereum DApps.

This planned protocol is part of Ethereum‘s proposed transition from the energy-intensive POW consensus algorithm to the PoS algorithm. Read more about their comparison in “Proof of Work vs Proof of Stake Comparison”.

The PoS algorithm employs ’Stakers’, who will stake their Ethers for transaction validation, hence they have skin in the game. This is unlike POW, where miners may not own any Ether at all. The amount of stake and the duration of it determines the priority a Staker gets.

However, if malicious stakers buy a lot of Ethers and stake them, the likelihood of their selection as staker is high, and they can manipulate transactions. The Casper protocol will set some rules to prevent them, as follows:

  1. The Ethers staked will be locked for a period;
  2. The protocol will confiscate Ethers of malicious stakers, and bar them from staking again.

The transition to Casper will take a while and go through phases. Ethereum community has recently launched the first release called Casper Friendly Finality Gadget (FFG), and the client testing has begun. Ethereum still uses the POW, however, validators test the PoS mechanism every 50 blocks.

The next release will be Casper Correct-by-Construction (CBC), with a partial specification of the final protocol. The Ethereum community will collate the lessons they learn from the FFG and CBC phases, and finetune Casper further before the final transition. Read more about these phases in “Ethereum Launches First Release of Casper, Client Testing Begins”.

Raiden Network: 4th option to scale Ethereum DApps

“Raiden Network” is an off-chain solution to scale Ethereum DApps. Nodes participating in this network can open a “state channel” and communicate with each other using it. This is designed for payment transactions.

Not all transactions they execute through this channel are recorded in the ’root‘ blockchain, only a periodical summary is recorded. This could be very useful for regular small payment transactions, for e.g. subscription to a service.

Off-chain transactions require significantly less “Gas”, which makes it cheaper for the users. Also, since they don‘t congest the mainnet, it contributes to improved scalability.

While these are important advantages, there is a limitation. Only users with a “state channel” open between them can transact using it.

Germanys‘ Brainbot Technologies AG, a blockchain start-up, is developing it. The project is under development, and the release date isn‘t clear. Read more about this project in “What is Raiden Network Token? A Beginner‘s Guide”.

Sharding: the 5th Ethereum blockchain scaling tip

’Sharding’ is originally a database management concept. Horizontal portions of the database are stored in separate server instances appropriate indexing. At the time of the query, the indexing helps in loading data from the appropriate partition.

This makes the database more efficient. Read more about database sharding in “Database sharding explained in plain English”.

In the case of a blockchain network, sharding will mean the following:

  1. A group of nodes will only store data of one horizontal portion of the blockchain database, i.e. one shard.
  2. Different groups of nodes will store different shards.
  3. Transactions and transaction validation will be confined to one shard.
  4. Since nodes don‘t load the entire blockchain data and don‘t participate in all transaction validation, it will improve scalability.

Read more about blockchain sharding in “Blockchain FAQ #3: What is Sharding in the Blockchain?”. Sharding can‘t work with the POW algorithm. Nodes in one shard can‘t even see all transactions, hence they can‘t participate in every transaction validation.

Hence, PoS algorithm is a prerequisite of sharding. Each shard must have its‘ stakers, who will take the responsibility to validate transactions within that shard.

While this is a scaling best practice, there are a few limitations, as follows:

  1. Sharding is not easy to design and implement. It‘s a complex subject even in the database management domain, where it‘s not all that new.
  2. Transactions are confined within a shard.

As of now, you can only use sidechains to scale Ethereum DApps since the others are still under development or transition. However, follow the Ethereum developer community closely so that you can keep pace with developments concerning Casper, which promises to be an important long-term solution.

Download Our Project Specification Template