FCM push with high priority to topic comes with delay

Dima Rostopira picture Dima Rostopira · Nov 14, 2016 · Viewed 7.1k times · Source

I'm sending push messages to small group of devices (less than 5) subscribed to one topic with priority parameter set to high

High priority. FCM attempts to deliver high priority messages immediately, allowing the FCM service to wake a sleeping device when possible and open a network connection to your app server. Apps with instant messaging, chat, or voice call alerts, for example, generally need to open a network connection and make sure FCM delivers the message to the device without delay. Set high priority only if the message is time-critical and requires the user's immediate interaction, but beware that setting your messages to high priority contributes more to battery drain compared with normal priority messages.

But when I put device to IDLE state it comes with big delay. On Nougat 7.1 delay is more than 10 mins. This type of push requires delay less than 10 secs.

Setting time_to_live to 0 solves issues only on Marshmallow. Nougat still failing.

So, I see only 3 possible causes of issue

  1. Messages sent to topic can't be high priority. But sending independent messages to each device will increase app-server load. I need to load fresh token from Firebase Database, so the result will be - 10 http requests for 5 users instead of 1.

  2. App must be in whitelist. But according to docs it's not acceptable, if I'm using FCM. And I don't want it, because it will cause battery drain.

  3. Bug? https://github.com/firebase/quickstart-android/issues/100

If real cause is first, then why it isn't described in documentation?

Answer

Dima Rostopira picture Dima Rostopira · Nov 15, 2016

Issue solved by setting time_to_live to 0. According to docs, this set's priority to "now or never"

Another advantage of specifying the lifespan of a message is that FCM never throttles messages with a time_to_live (TTL) value of 0 seconds. In other words, FCM guarantees best effort for messages that must be delivered "now or never." Keep in mind that a time_to_live value of 0 means messages that can't be delivered immediately are discarded. However, because such messages are never stored, this provides the best latency for sending notification messages.

UPD: solved only for Marshmallow. On Nougat is still an issue.

UPD2: just don't use topics, they aren't intended for sending pushes without delay.