user14385534
user14385534

Reputation:

Reading the Realtime database directly VS using Cloud Functions

I have been reading this article about reading the realtime database directly vs calling cloud functions that returns database data.

If I am returning a fairly large chunk of data e.g. a json object that holds data representing 50 user comments from a cloud function does this count As Outbound Data (Egress) data? If so does this cost $0.12 per gb per month?

The comments are stored like so with an incremental key.

comments: [0 -> {text: “Adsadsads”},
1 -> {text: “dadsacxdg”},
etc.]

Furthermore, I have read you can call goOffline() and goOnline() using the client sdks to stop concurrent connections. Are there any costs associated with closing and Opening database connections or is it just the speed aspect of opening a connection every time you read?

Would it be more cost effective to call a cloud function that returns the set of 50 comments or allow the devices to read the comments directly from the database But open/close before/after each read to the database, using orderByKey(), once(), startAt() and limitToFirst()?

e.g something like this

ref(‘comments’).once().orderByKey().startAt(0).limitToFirst(50).

Thanks

Upvotes: 2

Views: 509

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598837

If your Cloud Function reads data from Realtime Database and returns (part of) that data to the caller, you pay for the data that is read from the database (at $1/GB) and then also for the data that your Cloud Function returns to the user (at $0.12/GB).

Opening a connection to the database means data is sent from the database to the client, and you are charged for this data (typically a few KB).

Which one is more cost effective is something you can calculate once you have all parameters. I'd recommend against premature cost optimization though: Firebase has a pretty generous free tier on its Realtime Database, so I'd start reading directly from the database and seeing how much traffic that generates. Also: if you are explicitly managing the connection state, and seem uninterested in the realtime nature of Firebase, there might be better/cheaper alternatives than Firebase to fill your needs.

Upvotes: 2

Related Questions