What is a better solution for fetching multiple user profile image url

I wonder which solution is mostly used when fetching multiple user profile image. Especially in 'comments', which display multiple user's discussion, with their nickname and profile image.

I was saving user profile image at Firebase/profileimg/{uid}, and if a user updates the image, it replaced with new value. So only 1 profile image last per 1 user.
And if the user leave comment, I add the comment with user's current information required for comment(nickname, profileImg) together. Because I didn't want to fetch user's info whenever I fetch each comment.

Ex)

{
  author: { 
       uid: ****,
       profileURL: 'https://...',  
       nickname: 'foobar'
  }, 
  body:  "", 
} 

But the problem is, when user update their profile, photoURL of earlier comments are became obsolete, and image link is broken.

And now I am in front of 2 choices,

  1. keep user's old profile image alive in the storage so that the image link is still alive. (costs more storage)
  2. Save only user's uid in comment object and fetch the latest profile image from uid. (costs more read)

In the aspect of cost, which is more efficient or more frequently used? Thank you for reading. Waiting for senior dev guru 🙏


Solution 1:

Update:

Best option: Option#1:

You can save the generated link of the uploaded image to the Cloud Firestore database.

You can update the profileURL in the user profile and all user's previous comments too when the user uploads the new image.

Option#2:

You can also try this:

When the user updates the profile image, update all the previous comments to have the new profileURL.

You will always have to do this in two steps:

  1. Run a query with your conditions to determine the document IDs
  2. Update the documents with individual updates, or with one or more batched writes.

You can read more about it here:

https://stackoverflow.com/a/48950404/8213343

Option#3:

I would say your first choice is better than the second one. -- keep user's old profile image alive in the storage so that the image link is still alive. (costs more storage) - because the cost of storage is comparatively cheaper.

Here are the pricing details:

Document reads: $0.06 per 100,000 documents

Document writes $0.18 per 100,000 documents

Document deletes $0.02 per 100,000 documents

Stored data $0.18/GiB/month

https://firebase.google.com/docs/firestore/pricing

Reads, writes, and deletes

You are charged for each document read, write, and delete that you perform with Cloud Firestore.

Charges for writes and deletes are straightforward. For writes, each set or update operation counts as a single write.

Charges for reads have some nuances that you should keep in mind. The following sections explain these nuances in detail.

Listening to query results

Cloud Firestore allows you to listen to the results of a query and get realtime updates when the query results change.

When you listen to the results of a query, you are charged for a read each time a document in the result set is added or updated. You are also charged for a read when a document is removed from the result set because the document has changed. (In contrast, when a document is deleted, you are not charged for a read.)

Also, if the listener is disconnected for more than 30 minutes (for example, if the user goes offline), you will be charged for reads as if you had issued a brand-new query.