There’s really no way in Bubble to guarantee non-duplicated sequential numbers, due to race conditions, as there is no way to utilise database-locking.

So anything you do here will never fully eliminate the risk of duplicates.

There are some ways to reduce the likelihood significantly, but you can’t get away from race conditions so there’s still always a chance of duplicates.

The real questions are:

  1. why do you need to use sequential numbers?
  2. What does it matter if there are duplicates?
  3. Can’t the invoices be specific to Users (still sequential, but just in relation to a User rather than the entire database)?
  4. Is it worth the considerable time and effort trying to build a complex queuing system to mitigate the risk of duplicates, rather than just creating a system where duplicates aren’t a problem.

If you really do need unique sequential numbers, then an external database is the solution where you can use transactions and database locking.

Alternatively you can build some kind of que-system, with additional checks after items are created, which can significantly reduce the likelihood of collisions (but anything done on the Bubble database is still subject to race conditions).

1 Like