5

I met a guy down the pub and he said it was better to code up everything yourself when you want to make a new L1 with millions of TPS as you could then have everything just the way you wanted it rather than using substrate.

What are the advantages of using a framework like substrate rather than coding all of a Layer 1 blockchain from scratch?

3 Answers 3

9

This is a very good question which I think requires a very long and extended answer.

Here are some really good reasons to use Substrate over building everything from scratch :

  1. It provides all the core components of a blockchain (Database Layer, Networking Layer, Transaction Queue, Consensus Engine, etc) which have been thoroughly tested since a very big amount of blockchains have been built based on that (Polkadot, Kusama, different parachains, etc).
  2. It is modular so you can add or remove functionality as you wish by choosing only the modules you need in your blockchain.
  3. It is extensible so if the existing modules do not cover your needs then you can write your own code and extend them.
  4. You can upgrade without hard forks (forkless runtime upgrades).
  5. The runtime can run in any platform since it is compiled into WASM/WebAssembly.
  6. It is open source.
  7. It is written in Rust so if your developers team are Rust developers that makes it easy to customise it.
  8. It has a lot of resources online that you can check and learn how to build what you need, docs, videos, wikis or tutorials like https://docs.substrate.io/tutorials/v3/
  9. You can easily convert your Substrate standalone chain into a Polkadot/Kusama parachain (with cumulus).
  10. It offers an Ethereum-compatible execution environment so in your Substrate chain you can host the vast majority of the Ethereum state transition function.

Here are some resources in case you would like to check all of the above points into more detail :

https://youtu.be/-6BBIr-DmI4

https://youtu.be/V9KfvhoqLJ4

https://medium.com/polkadot-network/polkadot-substrate-and-ethereum-f0bf1ccbfd13

5

What are the advantages of using a framework like substrate rather than coding all of a Layer 1 blockchain from scratch?

You don't need to write and test your own

  • P2p layer.
  • State and history databases.
  • Transaction fee accounting system.
  • Consensus algorithm: plugin anything you like, including PoW/Nakamoto consensus, or just use an existing state of the art PoS/pBFT variant that comes in Substrate, or use the Relay chain shared security model with Polkadot/Kusama or other relay chain, which also gives you interoperability.
  • Node API.
  • Smart contracting environment & languages, including EVM support if needed.
  • Validator tooling & telemetry.
  • Client libraries.
  • Block explorer.
  • Wallet implementations.
  • Caching layer (see Subsquid/Hydra/Subquery).

and to be honest, this is only the start of it when it comes to what you'll have to implement. Then there is the social side of it, which involves having to train developers from scratch to build with your whole new stack, compared to tapping into an existing and rapidly growing developer pool.

1

I do agree that theoretically writing everything from scratch allows you to get much better results than a pre-made framework. Besides that, Substrate has to make some sacrifices for the generality it provides.

Consider replicating Bitcoin in Substrate. Let's focus only on one facet of such a project — the database. To validate a bitcoin block, one only needs to store the set of UTXO. Bitcoin does not require a state trie. If you were to implement bitcoin on top of Substrate, you would store the UTXO in the state trie. That comes with the price of maintaining the state trie, e.g. computing the state root. Who cares about bitcoin, you may ask? The point is though that Substrate makes some assumptions for you. Those can fit your use case, or they can interfere.

If you take the logic to the extreme, you should not write programs for operating systems. Instead, write the programs directly for bare metal, forgoing an OS just because an OS makes choices that you might not want or need. That's not what we see in reality, though. It takes absolutely insane amount of effort and obscure knowledge. People do that but only when they absolutely have to and when they can afford that. Linux is good enough for the overwhelming majority of use-cases.

I think this analogy works here, so I will further develop it.

It takes enormous amounts of effort and expertise. You will have to fill in a database, trie, mempool, and VM, to name a few, and each of those is a rabbit hole of each own. Each component needs to be implemented, tested, optimized and maintained. That takes time and always more time than you expect (even after the adjustment).

Similar to Linux, there is space for reaping the fruits of economies of scale. More users make for more contributors. More contributors make for more quality software. Also, more quality software attracts more users. Many bugfixes are written with blood. Thousands of developers' serendipitous insights lead to innumerable optimizations. It's very hard to challenge Linux, even if your scope is way less general. Also, there is a point about a talent pool. There are certainly people who can write programs against Linux, and there are a decent number of kernel developers.

This is not to say that Substrate is in such a position currently, but it is on the way there. It seems to be the general dynamics of framework vs. roll-your-own solution.

Rolling your own blockchain is a dangerous endeavor accessible only to very well-funded entities and makes sense if the benefits are extremely high. If the team wants to innovate only on the STF (in Substrate we call it Runtime), there is not much sense in writing the blockchain from scratch. In the case something does not work well in Substrate for a particular use case, the team would be better off lobbying the change to make it work better or, in the worst case, forking Substrate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.