Hi everyone, I’ve been building bubble apps for just over a year now and have had great success until now.
One of my apps has a user fillable form, and when the form is submitted, a unique sequential number is generated. I do this as follows:
I created a data type of Global Env Conditions
Single entry with uniqueFormID as Name and a number field.
Every time the form is submitted, I schedule a backend workflow that does 20+ things, but the first step is to search for the number value of uniqueFormID, update it with +1 and then use the new number in the subsequent actions. I understand that the subsequent actions will wait, as they all use the result of step 1.
Recently, I’ve seen hundreds of duplicate numbers appearing and upon more reading figured out it’s due to race conditions where multiple users are submitting forms within a couple of seconds of each other.
I found a plugin that does database locking but it lacks any reviews and feels like overkill. Is there a way to:
- Run workflows in sequence as opposed to parallel? Specifically for just this workflow.
- Another way to sequentially create numbers with no possibility of duplication?
EDIT: Based on @mikeloc 's suggestion, I’d like to add:
- I have about 80000 entries, so the :make static option is problematic.
- The unique number cannot rely on the actual number of entries in the db, as entries are deleted (entries have statuses and various other boolean flags like pending or rejected, but they also do get deleted).
- I’m much less concerned about per-second sequence accuracy, and more about uniqueness. A precise order is not of critical importance, but randomizing would also be way too, well, random.
Thanks for taking the time!