Home > Software engineering >  Is there a cost effective way of backing up Firebase Firestore?
Is there a cost effective way of backing up Firebase Firestore?

Time:10-08

As I understand it, backing up a Firestore database incurs a read for every document. That seems incredibly expensive.

For example, let's say I have note taking app with 1000 users and every day each user creates 100 docs and reads 100 docs. The cost per month would be:

reads = 1000 * 100 * 30 * 0.036/100000 = $1.08 per month
writes = 1000 * 100 * 30 * 0.108/100000 = $3.24 per month 

That seems very reasonable, even inexpensive.

But let's say I want to create a daily backup to ensure customers don't lose their notes in case of some sort of failure.

After 1 year of use, the monthly cost of a daily backup will be:

reads = 1000 * 100 * 365 * 30 * 0.036/100000 = $394.20 per month

And it'll only get more and more expensive over time!

Does anyone have any recommendations on how to handle this? I know that the Realtime Database has backups that only cost storage, but I think for this type of app, Firestore is better in all regards except for backup costs.

CodePudding user response:

I apologize for answering this question like this, but you have your math wrong. You multiplied by 30 and 365. Which would give you the cost for about 30 years. Your cost to back up would be

reads = 1000 * 100 * 365 * 0.036/100000 = $13.14 per year

Correct me if I'm wrong. I may have misunderstood your problem.

Edit0: By the way, you can easily backup using the Cloud Firestore managed export and import service.

Edit1:

GCloud offers a service called BigQuery (its Google's framework for data analysis). Previously, what I used to do is what you describe in your question, exporting entire collections from Firestore to analyse in BigQuery. But now, you can configure real-time synchronicity between BigQuery and Firestore.

With the “Export Collections to BigQuery” extension, you can send realtime, incremental updates from any Firestore collection to BigQuery. It will listen for document changes in your specified Firestore collection, then exports the changes into BigQuery. In other words, the data in BigQuery is a mirror of your content in Firestore.

This functionality is described here (medium.com).

Edit2:

As discussed, the concern came up that should the data become corrupt in Firestore, it'll probably affect the data in BigQuery since it's updating in real-time.

To solve this, I recommend using Cron job to schedule daily exports from BigQuery. Exports from BigQuery are free of charge.

  • Related