Sequential Numbering, Race Conditions?

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:

  1. Run workflows in sequence as opposed to parallel? Specifically for just this workflow.
  2. Another way to sequentially create numbers with no possibility of duplication?

EDIT: Based on @mikeloc 's suggestion, I’d like to add:

  1. I have about 80000 entries, so the :make static option is problematic.
  2. 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).
  3. 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!

Hi there, @justen… if you haven’t seen this post before (the whole thread is worth a read, too), you should check it out.

Best…
Mike

1 Like

Thanks @mikeloc, I did read through the post as well as others where @keith gave his input. Here’s why I think (possibly erroneously) that my situation requires a different approach:

  1. I have about 80000 entries, so the :make static option is problematic.
  2. 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).
  3. 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!

Why doesn’t the records unique work for you?

Good question. The form submissions are turned into PDFs, included on invoices and referenced both online and offline by users.

Session 74567 is much more manageable to be referenced, searched and referred to as 1702603996211x656253275475206400 :smiley:

This topic was automatically closed after 70 days. New replies are no longer allowed.