Back to blog

Easiest Way To Update Data Without a Database

Easiest Way To Update Data Without a Database

Justin Hunter

When you’re building an app, you generally need two things every time. You need file storage (and retrieval) and a database. A lot of times, you’ll need authentication, but in almost every case, you need files and a way to query data. If your app is file-heavy, it would be nice if you could focus on that and not worry about the database. With Pinata Hot Swaps, you can.

With traditional object storage, you upload some data, you get a content identifier (in Pinata’s case, you get a content-addressed CID), and you can load the file through a global CDN (Pinata calls this a Gateway). But what happens when you need to make changes to that data? There are two options:

  1. With traditional storage, you can overwrite the file and use the original file path to load the content through the CDN.
  2. Alternatively, you could upload a new version of the content then use a database to track which version is the most up-to-date one.

Neither option is great. With option 1, you have to accept the fact that you lose the history of that content. Every time you overwrite the file, you lose the last version. With option 2, you have the overhead of running a database and the overhead of having to query that database before you can load your content. If you already run a database, this might be the option you take even though it’s not great.

With Hot Swaps, you might be able to eliminate your database entirely and create a third option for updating content. First, let’s understand how Hot Swaps works, then we can map it to how your app might operate.

Hot Swaps allows developers to update the content served based on its original content identifier (CID) while maintaining the file’s history. Here’s how it works. Let’s say you have uploaded the original copy of your data or file. You have the CID. This CID is all you need to be able to load the content through your Gateway CDN. Now, your app makes a change to this file and creates a new version. The app uploads that new version to Pinata. With Hot Swaps, you can simply swap the resulting CID from this upload with the original CID and you can still load the new content through the original Gateway path.

Let’s explore this through a diagram.

All you need to care about as a developer is the original CID. You can then load an infinite number of updated files through the Gateway CDN using that same CID. All while maintaining a history of past versions.

This paradigm allows developers to ditch the database in many cases. Even more, it allows developers to better manage both their static and dynamic content. It’s a powerful app development primitive included with every Pinata paid plan. You can read more about how to install the Hot Swaps plugin and how to use it here.

Happy building!

Subscribe to paid plan image

Share this post:

Stay up to date

Join our newsletter for the latest stories & product updates from the Pinata community.