Where to Build dApps - Layer 1 or Layer 2?

Other
Jan 22, 2024Reading Time: 8 minutes

What are the latest solutions for successful and future-proof dApp building? We provide you a comprehensive overview simplifying the benefits of layer-2 protocols and blockchain modular architecture. 

where-to-build-dapps-cover

When you venture into the world of building dApps, understanding where both Layer 1 and Layer 2 protocols fit is crucial. You should think of these as distinct architectural layers contributing to the functionality and scalability of decentralized systems. In essence, they are vital components in the blockchain architecture.

Choosing a blockchain architecture is a pivotal decision that requires careful consideration. One of the foremost questions you are likely to face is – Should I build on Layer 1 or Layer 2? We will explain these potential options in the following sections. Digesting this will help you navigate the right direction for your future endeavors. ‘The future is modular report’ by the Onchain research team also provides further information.

What are Layer 1 and Layer 2 in blockchain networks?

Layer 1 is the base protocol. It acts as the infrastructure, enabling other applications and protocols to build on top of it. So, Layer 1 is often referred to as the foundational blockchain network. 

For example, Ethereum, Cardano, and Solana are Layer 1 networks. 

With Layer 1 networks the deployed consensus mechanism involves trade-offs. These are between security, decentralization, and speed. These trade-offs are known as the blockchain trilemma. This is discussed later. 

The field of consensus mechanisms is always evolving. E.g., some networks prioritize decentralization and security at the Layer 1 level. And then they outsource speed-related functions to Layer 2 solutions.

You can think of Layer 2 as a supplementary layer that is built on top of Layer 1. In essence, it is an off-chain network residing on a Layer 1 network. Layer 2 networks enhance the efficiency of their underlying corresponding Layer 1 infrastructure. 

This Layer 2 extension is used to augment the performance of the Layer 1 network. This can result in lowering transaction fees and enhancing programmability. 

Arbitrum, Optimism, Polygon, and Starknet are some of the Layer 2 scaling solutions out there.

What is the difference between Layer 1 and Layer 2 in blockchain?

Certain strategies are used to address scalability and transaction processing challenges. For example, Layer 2 networks possess the ability to boost throughput. This can come at a cost, as it may impose a burden on the mainchain. And this could result in a compromise of security and decentralization in favor of increased throughput. 

To provide you with an overview, the following table below gives a comparison of both Layer 1 and Layer 2.

The limitations of Layer 1 solutions led to various research on scalability in Layer 2 protocols. For example, by the Ethereum foundation and various other entities. 

Using Layer 2 allows for authenticated off-chain transactions. In turn, this offers new features, which do not compromise any of the existing structures. Both have their upsides and downsides.

The future is modular – what is Layer 2 scaling?

The next step to be aware of is the advent of modular architecture. It comprises a multi-layered architecture, where the functions of the modules are separated. 

Modular blockchains are broken down into the following four different functions: 

  • Execution 
  • Consensus 
  • Settlement
  • Data availability 

An example comparison of the standard monolithic architecture and the modular structure is shown in figure 1.

Figure 1 – Monolithic vs Modular Architecture – Diagram source: celestia.org

These four functions are handled in separate protocols. It is possible to optimize these functions to perform their tasks separately. The result is a more customizable and scalable system, with no constraints on security and decentralization. 

So, you can now tailor your own environment here. And your upgrades will be more simple when enhancing components separately. This minimizes the chances of causing any major disruptions.

Naturally, there are pros and cons, although the advantages allow you greater flexibility. A customizable system can be created that provides a higher level of scalability. In turn, this offers a smooth interaction with different chains. 

The drawbacks require developers to have more software and framework experience. So it is more complex to construct from a security perspective. Nevertheless, you can make vast improvements on these individual layers. And this can be done by modular disaggregation of the core functions of a Layer 1 system.

For example, Lisk will be positioned as a Layer 2 ecosystem chain. It will have modular scaling via sidechains with an emphasis on onboarding applications. These will be related to real-world assets (RWA) and off-chain assets (OCA). And it will also include the creation of decentralized physical infrastructure networks (DePIN), on the blockchain.

Modular blockchains represent an important new milestone in the crypto arena. So using modular-based networks will provide you with the benefits from the network effects. And this will boost security and usability.

Bringing Layer 3 into the mix

The primary merit of a Layer 3 scaling solution lies in its ability to enhance scalability. And it does not require alterations to the existing blockchain infrastructures. But a key assumption persists within the blockchain trilemma, (see figure 2 below.) 

Each transaction necessitates on-chain settlement as fast as possible. Reducing the settlement times can provide a financial incentive. By enabling faster trading and other financial operations, this leads to an increase in profitability. This means that the blockchain system must not compromise on the on-chain settlement time (OCST). 

So, if we now introduce the OCST property, this leads us to a Tetralemma. In the Tetralemma framework, a system is capable of embodying 3 out of the 4 specified properties. See figure 3 below. 

Why do Layer 2s matter and why do we need Layer 2 solutions?

Layer 2 protocols aim to enhance the scalability and effectiveness of the blockchain. We’ve seen that, as the decentralized Web3 landscape expands, it encounters scalability issues. Layer 2 solutions tackle these by providing faster transactions and reduced costs, crucial for both your decentralized applications (dApps), and the Web3 ecosystem. You also end up getting the optimal performance out of your system.

Another area to consider about Layer 2 solutions is the dominance of Ethereum in this space. They have successfully capitalized the Layer 2 blockchain sphere. Ethereum’s Layer 2 tokens are built on a Layer 1 scaling solution. This is to address the scalability challenges. These tokens leverage off-chain or sidechain technologies. Transactions happen faster and cheaper compared to those directly on the Ethereum mainnet. 

Ethereum has a pioneering role in the smart contracts, and decentralized applications (dApps) arena. It has a vast and engaged community. It is the go-to platform for decentralized finance (DeFi), non-fungible tokens (NFTs), and enterprise Applications. This has resulted in its widespread adoption. The growing user base significantly boosts Ethereum’s network effects.

The move towards Layer 2 solutions in the crypto industry will only fortify its success further. As it is one of the most popular dApp development platforms, this resulted in various Ethereum Layer 2 rollup solutions coming to the foray. These consist of the likes of Optimism, Arbitrum, Polygon zkVM, and zkSync Era.

Building dApps on Layer 2

The reason why building on Layer 2 is advantageous comes down to scalability. To achieve this goal, using a Layer 1 solution needs higher hardware requirements. This may compromise decentralization and require significant changes to the Layer 1 protocol architecture. This could result in the project becoming time-consuming and cumbersome.

On the other hand, to address these pain points, many developers choose Layer 2 solutions. This results in a more flexible and faster alternative solution for their dApps. 

To achieve this we need to look at the key Layer 2 rollups that currently exist for Layer 2 scaling solutions.

ZK Rollups

Firstly, ZK rollups are an alternative solution. These also reduce transaction costs and increase scalability. Similarly, multiple transactions are consolidated and batched together. And this results in a rollup that can then be executed off of the mainchain.

Figure 4 – ZK Rollups – Diagram source: nervos.org

After completion, a concise summary of the changes made is submitted by a ZK rollup operator. This produces validity proofs that ensure the accuracy of the changes. These zero-knowledge proofs (ZKPs), are much smaller than the original transaction data. So it is easier, faster, and cheaper to verify them. 

These proofs are cryptographic protocols that allow off-chain transactions while maintaining validity. And they also safeguard the transaction data’s privacy and security.

Optimistic Rollups

Secondly, an optimistic rollup accumulates transactions on its chain and bundles them into a batch (rollup). It then submits them for execution on the mainchain. The term “optimistic” is used as these transactions are considered to be valid unless proven otherwise within a specified time period. This reduces the amount of computations, and results in lower gas fees. Furthermore, a “fraud-proof” mechanism is deployed. 

Figure 5 – Optimistic Rollups – Diagram source: nervos.org            

If misbehavior occurs by the block producers, then the transaction data must be accessible on the Layer 1 mainchain. Compared to zero-knowledge (ZK) rollups, this solution offers native support for smart contracts. So developers are easily able to deploy their dApps with only minor code adjustments on the Layer 2 network. 

Rollups-as-a-service (RaaS)

Finally, it is worth mentioning the emerging technology of rollups-as-a-service, (RaaS). This was inspired by the well-known analogy of software-as-a-service (SaaS.)  A RaaS product is designed to offer a simplified, elastic, flexible, pay-as-you-go model. This can consist of different rollups, that would be a custom-built solution These will reduce the complexity and time to complete your project. 

There are various RaaS providers out there that you can outsource this entire process to.

An overview comparison between optimistic rollups and ZK rollups can be seen in the table below:

We have covered the two primary L2s that stand out as clear robust solutions. Trade-offs exist between these 2 primary rollups. For example, optimistic rollups may result in higher latencies as compared to ZK rollups. This is due to a time delay occurring between the off-chain processing and the final mainchain verification. There is also a minimal chance that undetected fraudulent transactions might occur before they are contested. 

Alternatively, ZK rollups require more complex cryptographic computations. These are generally more technically complex to implement. And they may have higher computational costs.

Conclusion

In summary, Layer 1 provides a secure, robust, foundation. While Layer 2 provides the scalability required for efficient dApp development. The demand for dApps continues to grow, which underlines the importance of Layer 2 solutions. Layer 2 scaling solutions are a clear preferred choice today. 

This results in more sustainable and accessible blockchain systems that lead to broader integration of the web3 blockchain arena. 

Choosing the optimal Layer 2 solution is dependent on your project’s requirements. Several Layer 2 protocols currently exist. Nevertheless, your project team should research these further and choose the most suitable option. This decision rests on the delicate balance between scalability and security. 

Finally, from the ongoing research, even more secure and efficient solutions will emerge in the future. As they mature this will put the spotlight on regulatory requirements. This will likely further shape their adoption and future development.