question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FR: idempotency_key for messaging.send()

See original GitHub issue

Describe your environment

"firebase-admin": "~5.11.0" We use RTDB, Auth, Analytics, Storage, Messaging, PubSub

Describe the problem

It’d be useful if the messaging() product could include an idempotency_key for a message we wish to send to a user.

We use Firebase Functions to respond to RTDB events to send push notifications to users. Occasionally, we receive an error from the FCM service (e.g., Error: fcm.googleapis.com network timeout. Please try again.). We could enable retries on the Cloud Function to attempt to resend the push notification in the event of a function error. However, CF retries may loop for several days. Imagine a scenario where something in the function causes it to error, but after the message delivery is successful… the user may receive (many, many) duplicate push notifications.

We could persist the message ID to the RTDB or elsewhere after successfully sending the push notification, and then check this field before subsequent runs to ensure the message is only sent once.

However, what happens if the DB write fails for some reason? Ideally the FCM system would handle this for us if we provide an idempotency_key of some type. As duplicate push notifications would be a massively big problem for user experience, perhaps it could be something core to the FCM product.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hiranya911commented, Feb 18, 2020

The FCM team has closed that feature request as “Won’t fix”. They recommend including a custom-generated identifier in each message sent out (possibly as a data field), and then collapsing the duplicates at the receiver end:

this is solvable by the app developer creating a identifier for each message and including it in the payload. they can then collapse the dupes on their side. The duplication risk should be quite limited hence the recommendation to do this within the app.

If you wish to follow up further, report directly at https://firebase.google.com/support (mention the original issue ID 77217406)

0reactions
evgeny-myasishchevcommented, Nov 14, 2022

I am looking for exactly the same thing. Receiver-level deduplication will not help. It may only work if the app is active which is not always the case. It’s frustrating that the GCP team is refusing to add such a common feature in messaging systems forcing users to implement it, which is not always trivial and possible as other commenters mentioned.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Idempotent Requests - Stripe API reference
An idempotency key is a unique value generated by the client which the server uses to recognize subsequent retries of the same request....
Read more >
Idempotent requests - Shopify.dev
POST requests that process credit card payments, create billing attempts for subscriptions, or capture revenue details accept idempotency keys. GET and DELETE ...
Read more >
Idempotent Requests | Courier Docs
Learn how Courier's support for idempotent requests prevents sending email, SMS, and push notifications twice (works with SendGrid, Twilio, SES, and more).
Read more >
What is an idempotent operation? - Stack Overflow
In computing, an idempotent operation is one that has no additional effect if it is called more than once with the same input...
Read more >
Checkout.com API Reference
Cko-Idempotency-Key. string. An optional idempotency key for safely retrying payment requests ... Invalid data was sent.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found