When you plan to build a dApp, you need DB3 Network
Tags: dapp, typescript, web3, database
Published: 2023-01-13 13:18:06

# The Background
Ethereum has defined the novel dapp data architecture successfully.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvsaxgnoyaj2qb8eyu0v.png)

The novel dapp data architecture has the following improvement:

- **immutable**, when the protocol has been deployed, all the codes are immutable

- **transparent**, the smart contract can be verified by anyone and any organization

- **Permissionless**, everyone can use the protocol in the world
but **Ethereum has some limitations** e.g. scalability problems and high storage cost and **it can not cover the requirement of the storage-heavy dapps**. So a hybrid data architecture so called web2.5 is used for the storage-heavy dapps.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ugmago0ewk6q8kbp7g2.png)

The problem in the above is the hybrid data architecture will break the improvement that the web3 native application data architecture brings to us and the db3 network is trying to resolve the problem

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxsuyczx18bkdrsqu4fj.png)

# What’s the [DB3 Network](https://github.com/dbpunk-labs/db3)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lah8lkh5gzsgioiouwrs.png)

[DB3](https://github.com/dbpunk-labs/db3) is a community-driven layer2 decentralized database network with the following core features:

## Infinite Storage Space

Scalability is the key to the web3 explosion, [db3](https://github.com/dbpunk-labs/db3) will use the following strategies to achieve web3 scale. PC can meet the minimum system requirements so everyone can join the [db3 network](https://github.com/dbpunk-labs/db3) to provide storage space. Using dynamic sharding to achieve scale out. when a storage shard chain has not enough space to store mutation, it will split itself into two subchains.Using cold data archive to recycle storage space. history cold blocks and cold state data will be archived to FileCoin and the storage node will always has storage space to store new data.

## Blazed Fast and Provable On-chain Query
Currently, decentralization means bad performance but [db3](https://github.com/dbpunk-labs/db3) is trying to make a big improvement in performance. Merkdb 2 is the storage engine of db3 network and it not only has high performance but also the fast-proof generation.Geo distribution, the nodes in every storage shard are geo-distributed and the clients can execute querys against the nearest storage node. Query session, the first decentralized query protocol to resolve performance and incentive perfectly

## Crypto Native Data Ownership
In the decentralized network, only the private key owners can update their data and they can keep privacy by encrypting their data with the public key

## On-chain Programmable
Dapp developers can develop data processing contracts and deploy them to the [db3 network](https://github.com/dbpunk-labs/db3) just like developing data backend in web2

## Ethereum Guarded Security
[DB3 network](https://github.com/dbpunk-labs/db3) is a layer2 network on Ethereum and all the assets are guarded by Ethereum.

## db3.js-Developer-friendly SDK
db3.js is the db3 network 2 javascript API and you can write and query JSON documents against the db3 network with db3.js and you can combine the web3.js and db3.js to build a fully decentralized storage-heavy application. the web3 developers can use this API to put and get documents with the db3 miner node directly.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc5eh7x6jui8m9jkaw1o.png)

```
request.onsuccess = function () {
  console.log("Database opened successfully");
  const db = request.result;
  // 1
  const transaction = db.transaction("cars", "readwrite");
  //2
  const store = transaction.objectStore("cars");
  const colourIndex = store.index("cars_colour");
  const makeModelIndex = store.index("colour_and_make");
  //3
  store.put({ id: 1, colour: "Red", make: "Toyota" });
  store.put({ id: 2, colour: "Red", make: "Kia" });
  store.put({ id: 3, colour: "Blue", make: "Honda" });
  store.put({ id: 4, colour: "Silver", make: "Subaru" });
  //4
  const idQuery = store.get(4);
  const colourQuery = colourIndex.getAll(["Red"]);
  const colourMakeQuery = makeModelIndex.get(["Blue", "Honda"]);
  // 5
  idQuery.onsuccess = function () {
    console.log('idQuery', idQuery.result);
  };
  colourQuery.onsuccess = function () {
    console.log('colourQuery', colourQuery.result);
  };
  colourMakeQuery.onsuccess = function () {
    console.log('colourMakeQuery', colourMakeQuery.result);
  };
  // 6
  transaction.oncomplete = function () {
    db.close();
  };
};
```

## The overview of [db3 network](https://github.com/dbpunk-labs/db3) architecture

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ewis00x0r7gcjeu0tjqh.png)

## Why does [DB3 Network](https://github.com/dbpunk-labs/db3) focus on the storage-heavy dapps
image

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0xo8epkhmfosifh2tr22.png)

The more dynamic data the dapp used , the more users that the dapp will onboard.So we think the storage-heavy dapps are the future of web3

## Other Decentralized Databases
_**the graph**_, a decentralized on-chain indexer
_**Locutus**_, a decentralized key-value database
_**ceramic network**_, a decentralized data network that brings unlimited data composability to Web3 applications
kwil, the first permissionless SQL database for the decentralized internet
_**spaceandtime**_, a decentralized data Warehouse

if you are interested in the db3 network, **please give us a star on [GitHub](https://github.com/dbpunk-labs/db3)**