Firestore Client SDK vs Cloud Functions API

160 views
Skip to first unread message

Fawad Masood Desmukh

unread,
Mar 18, 2020, 11:21:34 AM3/18/20
to Firebase Google Group
Hi,

I'm wondering how do you decide between directly accessing the firestore database inside an app via the client SDK vs making indirect calls to cloud functions that access the database for you?

John Rodkey

unread,
Mar 18, 2020, 11:33:21 AM3/18/20
to fireba...@googlegroups.com
This really depends on your use case, but I generally prefer to use the client SDK when interacting with Firestore. There are many benefits to using the client sdk including rules, listeners, client cache, offline support, etc.  

Cloud funcs or CloudRun are extremely useful for cases where you may not want to return all of the data in your documents "projections".

Other things to consider - by invoking a Cloud Func you will incur the additional expense of the function usage. You will need to create your own rules check - Cloud Funcs use the admin SDK to interact with Firestore and bypass the rules engine used by the Client SDK.


On Wed, Mar 18, 2020 at 10:21 AM Fawad Masood Desmukh <fawadmaso...@gmail.com> wrote:
Hi,

I'm wondering how do you decide between directly accessing the firestore database inside an app via the client SDK vs making indirect calls to cloud functions that access the database for you?

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/2041e6b2-9a07-49d0-b4a3-79db978d27e2%40googlegroups.com.

Fawad Masood Desmukh

unread,
Mar 18, 2020, 1:25:25 PM3/18/20
to Firebase Google Group
Hi!

Thanks for the informative reply. My use case is essentially just CRUD for a mobile app really.

My only concern with using the client sdk was seperation between front end and backend. I suppose if I want to do some filtering or data enrichment/validation I'd have to modify the client code and then release a new app version if that makes sense whereas having the cloud functions would separate that process?

Would it make sense to do all reads via the client sdk but say all writes through the cloud funcs?

You do make a good point about billing. Cloud func usage should be a little pricier.

Sam Stern

unread,
Mar 18, 2020, 1:41:02 PM3/18/20
to Firebase Google Group
HI Fawad,

All of what John said is 100% correct and it's good advice!  I just want to go a little further.  The magic of using Cloud Firestore or Realtime Database is that your database IS your API.  We handle authentication, serialization, caching, flaky networks, realtime sync, etc for you on all platforms.  If you use your DB through a Cloud Function (or any other server) you're really dropping most of the magic.  There's nothing wrong with that, but I do think you'll end up wanting some of the things that the Firestore SDK provides for you and when you do you'll have to write it yourself.

Normally I do as much direct-client-access as possible and only use backend operations for the following cases:
  • Long-running operations that may not finish on the client in a reasonable time (large deletes, for example).
  • Sensitive operations that need more detailed authentication than security rules can provide.
  • Operations that need moderation.
  • Interactions with 3rd party services, for example processing payments.
I hope that gives you something to think about!
- Sam

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages