0

Update:I found this isn't main reason of increase usage.


I'm already using notification key to send notification.And I knew is that can't subscribe notification key to a topic.But we need a user can login same account on multiple devices. So I decide save notification key on realtime database.

enter image description here How my application work is when a user send a message to chatroom then cloud function triggered and read data once(group_chatroom_notification_keys/chatroom_id_1) to get all user_notification_key_n and send notification to each user. Problem is send every message need read chatroom all notification key again.This way increase so much realtime database GB downloaded.I paid 35% of earn to google every month now.

I also a bit confuse this doc say:

"For fast, secure delivery to single devices or small groups of devices, target messages to registration tokens, not topics."

what does it mean secure delivery? If I using chatroom_id as topic and subscribe all chatroom users token to topic for reduce the cost. Then chatroom notification data will steal by other device? because all chatroom should be private and I don't know how to reduce the cost correctly.

Someone have better way to do this? The cost for this is necessary?

1
  • Why not subscribe the user to the chatroom_id. I think you are being charged for the reads and writes to the database, not for the notification. Maybe you are fetching all the chat instead of the latest messages using pagination. Just a thought. Commented Feb 11, 2019 at 11:27

1 Answer 1

1

You shouldn't be reading keys again and again. I have build private chat rooms app too. The way I used it is:

When user open chat room I load all users key only once. Now no matter how many times I Send message I pass all loaded keys to Cloud functions and CF fire notifications. I hope it helps and save you some data usage.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer.Do you mean load all users key only once on device then send every message with all loaded keys.but CF still need to load all loaded keys every times from RT database still cost usage isn't it? can you explain detail about your answer or something I misunderstand .
No you pass already loaded keys to CF. You can pass arraylist of keys to CF as parameters. Search how to pass params to CF
Oh. You mean just using https.onCall trigger call CF from app directly. not pass to RT database then trigger CF?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.