System design is a broad field. There is a huge amount of resources scattered around the internet on the principles of system design. This repository is intended to be a collection of the various aspects that are relevant to both traditional system architecture (web2) and decentralized system architecture (web3), but also how the former can be simplified through the use of blockchain technology. To this end, the web3 area of the repository is being continuously expanded.
In the Web2 paradigm, building an application involves a multi-layered architecture, often requiring centralized servers, databases, load balancers, and authentication systems. This design process, while robust, comes with significant overhead in terms of infrastructure, scalability, and security challenges.
On the other hand, Web3 offers a paradigm shift by decentralizing these components. By leveraging blockchain technology, decentralized storage, and user-controlled wallets, Web3 eliminates the need for many traditional intermediaries. This can simplify the process of delivering applications while providing enhanced transparency, security, and user ownership.
Learning how to design scalable systems will help you become a better engineer.
-
Define the requirements and scope for your Web3 application. While some aspects overlap with Web2, Web3 introduces decentralized elements that must be considered. Ask specific questions to clarify use cases and constraints:
- Who are the users, and what value does decentralization bring to them?
- How will the application leverage blockchain and decentralization?
- Which blockchain or layer-2 solution will be used?
- What types of interactions will occur with smart contracts?
- What are the gas cost implications for these interactions?
- How will users authenticate (e.g., wallet-based or account abstraction)?
- What data will be stored on-chain versus off-chain?
- How will scalability and latency requirements be met?
-
Outline a high-level design for your Web3 application, focusing on decentralized components and how they interact with users and the blockchain.
- Key components to sketch:
- Frontend: Hosted on decentralized storage (e.g., IPFS, Arweave) or via serverless deployment.
- Smart Contracts: Define core logic and operations, deployed on the blockchain.
- Off-Chain Data: Consider indexing solutions like The Graph for querying blockchain data efficiently.
- Wallet Integration: Plan for user interaction with wallets (e.g., MetaMask, WalletConnect).
- Justify your choices:
- Why this blockchain? (e.g., EVM compatibility, transaction costs)
- Why this storage solution? (e.g., decentralized or hybrid storage)
- Key components to sketch:
-
Dive deeper into the decentralized and hybrid components of your Web3 application:
-
Smart Contracts:
- Define business logic and immutable state.
- Ensure gas-efficient design for transactions.
- Follow standards (e.g., ERC-20, ERC-721, ERC-4337) if applicable.
- Conduct thorough audits for security.
-
Frontend:
- Design a user-friendly, Web3-aware interface.
- Integrate wallet support for authentication and transactions.
- Optimize for decentralized deployment (e.g., serverless, IPFS).
-
Off-Chain Data and Indexing:
- Use tools like The Graph for efficient querying of blockchain data.
- Implement off-chain storage for large or frequently updated datasets.
-
Interaction Flow:
- Ensure seamless user interaction with smart contracts (e.g., transaction signing).
- Consider fallback options for users with limited blockchain experience.
-
-
Address potential scalability issues in your Web3 application, focusing on the blockchain and decentralized architecture:
-
Blockchain Scalability:
- Choose a blockchain with high TPS or use a layer-2 solution like Arbitrum or Optimism.
- Optimize smart contracts to reduce gas usage.
-
User Onboarding and Experience:
- Implement account abstraction to simplify wallet management.
- Provide clear UI/UX for transaction statuses and gas fee management.
-
Data Scaling:
- Use decentralized or hybrid solutions like IPFS and cloud storage for off-chain data.
- Cache frequently accessed data locally or via distributed networks.
-
Frontend Performance:
- Employ decentralized CDNs or peer-to-peer networks for low-latency access.
-
Gather requirements and scope the problem. Ask questions to clarify use cases and constraints. Discuss assumptions.
- Who is going to use it?
- How are they going to use it?
- How many users are there?
- What does the system do?
- What are the inputs and outputs of the system?
- How much data do we expect to handle?
- How many requests per second do we expect?
- What is the expected read to write ratio?
Outline a high level design with all important components.
- Sketch the main components and connections
- Justify your ideas
- Generating and storing a hash of the full url
- Translating a hashed url to the full url
- Database lookup
- API and object-oriented design
Identify and address bottlenecks, given the constraints. For example, do you need the following to address scalability issues?
- Load balancer
- Horizontal scaling
- Caching
- Database sharding
Credits and sources are provided throughout this repo.
Special thanks to: