My favourite database for Web3: Xata

As developers building for the decentralized web, we often wonder how our applications and projects will be received by the community. Decentralization means different things to many people. Some people advocate for total anonymity while others use the term "Web3" as fresh coat of paint over a traditional product.

Adding to the challenge of this question is the fact that blockchains are really bad as databases! This poses the question: how do we keep a balance between decentralized values and application performance?

Let's try to answer this question and see how we can approach it!

Should we keep everything on the blockchain?

Blockchains that boast smart contract features are a weird creature. They are a (slow) crossing between a serverless function and a database. The have the capacity to write elements to storage but they can also run computations.

If you decide to only use smart contracts as your backend, keep the following in mind:

Blockchain systems are slow!

You have to be ready to handle that slowness. Be sure to be proactive in your UX and UI development and include good loading states!

As for myself, I prefer to stay away from this purist approach. I look for a good balance between decentralization and user experience.

I think this balance can be summarized like this:

Keep the blockchain as the source of truth, supplement other features with an healthy dose of modern databases.

For me, that dose of modernity is Let's explore some useful tips on using Xata's wonderful features to achieve the balance described above. We'll be exploring a common usecase in Web3: An NFT Allowlist. (Explore the code here).

Usecase: Implementing an allowlist on the blockchain and Xata

Let's imagine a situation where you want to create an NFT community and you want to invite people to join that really really exclusive community.

Girl saying you can't sit with us, quote from meangirls

The typical NFT project would approach this with a spreadsheet of wallets that represents their allow list. They would then create a smart contract (with a merkle tree or similar data structure) that implements the allow list and that would be the end of the story.

I would like to propose improve this approach with tips to achieve the balance I described above.

Tip #1: Drop the spreadsheet.

Groups typically will converge to a spreadsheet as not everybody has coding skills on a team. This is a great tool to use for managing the allow list.

Your team will likely need to communicate with users on Twitter, Discord and other channels to get the users to join the community. They will start to expand this spreadsheet to fit the needs of their tasks.

Within weeks, you will now have little islands of knowledge in different areas of the spreadsheet that you can't control. Xata solves this problem by looking like a spreadsheet but it is a database. Meaning there is still an enforcable schema to structure your data.

A database on Xata that looks like a spreadsheet

Switching to Xata will give your non technical team members a good tool to manage their workload but will give you insurance and control over your data format.

Tip #2: Treat your DB as a read replica of the blockchain.

When you are ready to launch your project, you will need to generate the allow list. Once done, the source of truth for the allowlist becomes the smart contract holding it.

That does not mean that your database is useless! Let's explore this scenario:

Architecture of the project. Merkle tree and allowlist

In this scenario, the application will read the allow list from the database to provide a smooth experience to the user. The allowlist will be enforced by the smart contract when the user mints.

Working to supplement the smart contract, the database simply helps speed up read operations since it mirrors the data on the blockchain.

Tip #3: Be transparent.

With your shiny database, you have the ability to create amazing user experiences! With great power comes great responsibility!

Adding a database to an NFT project is not a freepass to create the next Facebook!

Communicate early to your users what data you intend on storing outside the blockchain. This will allow them to opt out of your project if they prefer to stay anonymous.

When you are storing data off the blockchain, you should be transparent about what you are storing. Users in Web3 have come to expect a level of privacy that a traditional development approach does not provide.

This is where you need to be careful about what you are storing. If you collect extra information like a Discord id or an email address, you will be able to identify the user. You should communicate this to the user.


I hope you found this article helpful and that you have an idea of how to use Xata to build a decentralized application. Please support my efforts by following me on Twitter!