Notify all users in the database within a reasonable time

The goal is to notify all users in the database at the end of a giveaway whether they’ve won, or not. (There are various other functions that need to run for each user, like crediting some of the giveaway entry cost back to them etc. but let’s stick to the basics.)

Users are notified by creating a record in the Notifications table. So at the end of a giveaway, the winner is instantly notified by creating a record, which then pops up on their end. But we would like to notify all the other users that they did not win this time, but we credited some funds back etc.

Let’s break down the problem.
Bubble doesn’t allow for bulk creation of database records.
Therefore we can create a recursive backend API workflow. (ouch) Add the user count (those who need to be notified) as the starting parameter, then have the function create a notification and call itself until we go through all users.
After a quick test, this process takes ~0.4 seconds per iteration to run, even if we schedule the workflow without delay. So if we were to notify 10000 (I know, very optimistic number) users, that would take us over an hour.

When our giveaways end, we want to notify our users immediately whether they’ve won or not.

I would appreciate any input on how to solve this problem any other way.
:sun_with_face:

Try using the data API bulk create action (you’ll still need to run a recursive workflow, but it should be a lot faster)…

Hey @chiprana ,

I think for the instant notification part, I’d do the following:

  • Save who won somewhere in the database.
  • When anyone logs into the app or opens up the page to see this “notification”, it does a real-time check: Is the current user the winner? If yes > great, show a message. If no > ok, show a different message and let them know they’ll be credited soon.

So, rather than waiting for a notification record to be ready, you just do a real-time conditional check. You can still run a background recursive flow to create the data you need (“permanent” notification record, credit, etc.), but if thousands of users are logging in to check if they won or not, this will be a more instant way of letting them know.

Even better – you could have a yes/no field on the user. If won, field = yes. This way, you’ve eliminated the need to search at all.

Just a thought!


Cheers, Gaby
Co-Founder at Coaching No Code Apps
Free Bubble Masterclass
Private Help

2 Likes

This should be a sufficient trick to instantly notify them until the other records are processed. This temporary notification will have to be created regardless of what page they open, but I realised I can put a Page load event on a reusable element like our notifications panel.

The winner is stored in the Giveaway object itself, so in case somebody is watching the countdown on the Giveaway page it is going to update instantly and they will see who the winner is without having to refresh.

Thank you Gaby