1

I am having a situation that everyday there will be around 1000 rows of data generated from postgresql db. These data will be served for frontend, which will be frequently call.

Actually for each time the front page re-rendered, I need to randomly fetch 100 rows from it.

For my knowledge, I have two choices to achieve what I want.

  1. Use Cloud Storage, generate a json file and save it in storage. Each time I just fetch the data by storage.bucket('my-bucket').file('my-file.json').createReadStream(); and pick 100 rows to generate front page.

  2. Use Firestore, save 1000 rows data, pick 100 rows by queryRef = postsRef.whereField("random", isGreaterThan: random).limit(to: 100)

I have no idea how to judge which one is more suitable for my case.

I think second method need more cost, as Firestore priced by read/write times. But probably with better performance. Is this true?

MT-FreeHK
  • 2,462
  • 1
  • 13
  • 29
  • How do you intend to measure performance? What exactly are you trying to optimize? – Doug Stevenson Apr 11 '19 at 02:57
  • 1
    If the data doesn't change frequently, Cloud Storage is likely the more economical choice. If the data changes are under your control, Firebase Hosting might actually be a better option. See https://stackoverflow.com/questions/37482907/firebase-differences-between-realtime-database-and-file-storage – Frank van Puffelen Apr 11 '19 at 03:01
  • @DougStevenson, I am trying to optimize the querying speed with reasonable price. For example, if using firestore is just insignificantly faster, than I probably will stay with Storage. – MT-FreeHK Apr 11 '19 at 03:34
  • @FrankvanPuffelen, thx, this post help me clarify the difference. So let's say if some columns in data are mutable, I better use Firestore. However, if it is just a static file, use Storage. Am I right? Also, the difference on querying speed is neglectable, right? – MT-FreeHK Apr 11 '19 at 03:36
  • There is no querying support in Storage or Hosting. Both of those only provide direct file lookup, so you'd have to precalculate the rows you need and write them into a file. – Frank van Puffelen Apr 11 '19 at 13:05

1 Answers1

1

If your items are not very big, then you are probably better off putting the compressed file in Cloud Storage (or better yet, Firebase Hosting). Uncompress and cache the file on the client to reuse later if necessary.

As usual, with all performance related optimizations, benchmarking your options is really the only way to know what's actually best.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441