Jonas
Jonas

Reputation: 7885

Using Firebase Functions for Rest Api vs Doing it on the Client?

I was wondering if it would be a good idea to create some rest endpoints with firebase function instead of handling everything on the client. I would create endpoints for more complex queries where I load documents for every document in a collection and return it in one big json object.

The main advantage this way would be that I wouldn't need to write the code for every app (Which in my case a flutter app and a vue web app).

However I would have to pay for functions in addition to the database costs. When doing everything on the client I would save the functions cost. However I can't estimate how much that would be yet.

Are there any mayor difference when using functions instead of doing the same things on the client?

Are there any other (dis)advantages?

Upvotes: 1

Views: 1056

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598797

Using Cloud Functions to encapsulate some of the more complex logic of your application code is quite common.

Advantage are that you only have to write the code for one platform (whatever language you run in Cloud Functions) and can update the code without having to tell your users to update the app. And it's definitely simpler for certain scenarios when you don't have to reason about all clients accessing your database at once.

A disadvantage is that calling Cloud Functions requires that the client is online. If you have the calling logic in the client itself, it can also run while the client doesn't have internet.

I am personally a fan of using a database (either the Firebase Realtime Database or Cloud Firestore) as a medium between my client and the Cloud Functions backend. So my client writes to the database, which then triggers Cloud Functions. The Cloud Function writes a result to the database, which the client listens to. That way I get some of the offline handling of the database SDKs, with the added benefits of Cloud Functions.

Upvotes: 1

Related Questions