dontknowhy
dontknowhy

Reputation: 2866

Firebase, Client Server-Side vs Cloud Functions Server-Side

assume there is a chat app that needs to delete chat message documents when total number of documents became a 5. yes I saw this example in guideline

but can I do this on client server-side on Android?(not cloud-functions) like this

db.collection("chat").orderBy("something").get(){
  if(task.getResult().getDocuments().size()>5){
    db.collection("blahblah").document("blahblah").delete()....
  }
 }

is there any disadvantage for this? if I do these things not on cloud-functions server-side

thank you (I also saw the question that looks like similar to this question, but that`s not my case)

Upvotes: 1

Views: 507

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317467

The disadvantage is that you're making the client app do the work, when you could instead do it more efficiently in Cloud Functions. The user pays the cost against their data plan by downloading all the documents in "chat", then deleting each document (requiring more round trips with the server). Sure, you could make the client do this work, but do you want them to pay for it in terms of data usage and speed? And what if other clients are each also trying to do the same thing?

See also my blog: Should I query my Firebase database directly or use Cloud Functions?

Upvotes: 1

Related Questions